Reputation: 105
Suppose I have two sets of scatter data, which I am plotting on x and y axes:
plt.scatter(x,y,s=2)
and each of these datasets has a histogram:
hist_x, bins_x, st_x = plt.hist(x)
hist_y, bins_y, st_y = plt.hist(y)
What I'm trying to do is display these histograms along each axis of the scatter plot, i.e. to show the distributions that the data has along each axis, in a single image.
How would one go about this?
Upvotes: 2
Views: 603
Reputation: 26
It seems to me that you're looking to use mpl for visualizations. If that's the case, I would suggest looking into the subplots class. You should be able to introduce a 2-2 grid and then fill those plots with the graph and the two distributions with appropriate rotation.
If, however, you're willing to try another package, I would suggest using seaborn. Here's an article on Visualizing Distributions using Seaborn from pydata that describes a method that does exactly what you're trying to accomplish.
I hope these point you in the right direction!
Upvotes: 1