Plotting joint probability of two random variable choices

0 votes

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?

Mar 21, 2022 in Machine Learning by Dev
• 6,000 points
1,521 views

1 answer to this question.

0 votes

Create pandas.DataFrame , you can use seaborn.jointplot to plot the joint probability.
You can play around with the kind parameter to get the plot you desire.

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

samples = 100

x = random.choices(population = [0.25, 0.75], weights = [25, 75], k = samples)
y = random.choices(population = [0.4, 0.6], weights = [4, 6], k = 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()

enter image description here
answered Mar 23, 2022 by Nandini
• 5,480 points

Related Questions In Machine Learning

0 votes
1 answer

Calculate the probability in R for sum of two dice rolls

By converting the outer values to a ...READ MORE

answered Apr 4, 2022 in Machine Learning by Nandini
• 5,480 points
2,039 views
0 votes
0 answers
0 votes
1 answer
0 votes
1 answer

Formula to calculate chance (probability) of a dice side based on its value

If I understand you correctly, you're looking ...READ MORE

answered Mar 17, 2022 in Machine Learning by Dev
• 6,000 points
730 views
+1 vote
1 answer

How to create plots using python matplotlib in IPython notebook?

I think you should try: I used %matplotlib inline in ...READ MORE

answered Aug 8, 2018 in Python by Priyaj
• 58,100 points
1,522 views
+1 vote
1 answer

How to handle Real-Time Matplotlib Plotting

To draw a continuous set of random ...READ MORE

answered Sep 26, 2018 in Python by Priyaj
• 58,100 points
16,341 views
0 votes
1 answer

How to increase plt.title font size?

Try the following : import matplotlib.pyplot as plt plt.figtext(.5,.9,'Temperature', ...READ MORE

answered Feb 11, 2019 in Python by SDeb
• 13,300 points
1,133 views
0 votes
1 answer

Understanding the probability of a double-six if i roll two dice

The chance of not getting a double ...READ MORE

answered Mar 23, 2022 in Machine Learning by Nandini
• 5,480 points
20,021 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP