# Plotting joint probability of two random variable choices

Solution for Plotting joint probability of two random variable choices
is Given Below:

If I have two variables, say

``````x = random.choices([0.25, 0.75], [25, 75])
y = random.choices([0.4, 0.6], [4, 6])
``````

how can I plot a 2D chart of with x-axis between 0 and 1, and y-axis between 0 and 1, to show the multiplied probabilities of the two variables, in a heatmap style format?

Thank you

You could create a `pandas.DataFrame` in which each line is a sample of the population, then you can plot the joint probability with `seaborn.jointplot`.
You can play with `kind` parameter to customize the type of plot you want.

## Complete Code

``````import random
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

n_samples = 100

x = random.choices(population = [0.25, 0.75], weights = [25, 75], k = n_samples)
y = random.choices(population = [0.4, 0.6], weights = [4, 6], k = n_samples)

df = pd.DataFrame({'x': x, 'y': y})

sns.jointplot(data = df, x = 'x', y = 'y', kind = 'kde', xlim = (0, 1), ylim = (0, 1))

plt.show()
``````
• `kind = 'kde'`

• `kind = 'hist'`