Open In Colab

fastkde.plot Example

This notebook demonstrates basic usage of fastkde.plot.

import numpy as np

try: 
    import fastkde
except:
    # install fastkde if not already installed
    !pip install fastkde
    import fastkde

For this example, we will generate data with the following relationships:

$$ x := \mathcal{N}(0,1)$$ $$ y := \mathcal{N}(x,1)$$ $$ z := \mathcal{N}(3x + 2y, 0.2)$$

""" Sample the three variables """
N = int(1e4)
x = np.random.normal(size=N)
y = x + np.random.normal(scale=1, size=N)
z = 3 * x + 2 * y + np.random.normal(scale=0.2, size=N)
""" Demonstrate the fastkde.pair_plot function """

fastkde.pair_plot([x, y, z], var_names=["x", "y", "z"])
../_images/5b10511cd44e529771e7457b3178a55c398876b12450dd0da1b50e581bb3e0ad.png
""" Demonstrate the pair_plot function, plotting conditional distributions """

fastkde.pair_plot([x, y, z], var_names=["x", "y", "z"], conditional=True)
../_images/b7d6979f611a6b2aaa41ee7c0780b0e8dd48bcd05176abb5fc3a804045a5299d.png