1

I'm comparing several histogram together, to evaluate the variance over the years:

enter image description here

The problem is that, while it shows the variance, it is hard to discern one type from another. I'm wondering what would be a better way to make this plot?

1 Answer 1

0

Those bars are not really stacked but overlapped. You can stack them by doing:

import matplotlib.pyplot as plt
import numpy as np

mu, sigma = 0,100
x1 = mu + sigma*np.random.randn(1000)
x2 = mu + sigma*np.random.randn(1000)
x3 = mu + sigma*np.random.randn(1000)

#Stack the data
plt.figure()
plt.hist([x1,x2,x3], bins=30, stacked=True, normed = True)
plt.show()

, which will result in this:

Stacked histogram

However to perceive a quantile variability in different distributions the boxplot is usually more adequate:

plt.boxplot([x1,x2,x3])
plt.show()

, results in:

boxplot for different distributions

You can also take a look into plots such as Probability Plot, or StackPlot. If you really need to compare the variance value (and not just the distribution globally) you can plot the lines for variance (or standard deviation if the order of magnitude is big) over your plots.

Sign up to request clarification or add additional context in comments.

4 Comments

My mistake. I wrongly used stack. It should be overlap. The boxplot would lose the histogram shape, which I think is really important here.
Than use the Violin Plot (matplotlib.org/examples/statistics/violinplot_demo.html). What features are you trying to compare (variance is just a number)?
No, no,no. I don't need to compare this specfic here, e.g. variance etc. . I just want to compare the histogram. The problem is that overlapping made them hard to look at. The half-transparent setting (alpha) makes it hard to discern one from another.
You have an argument that allows you to remove the fill from the bars in matplotlib histogram. Try adding histtype='step' as argument. It should only show you the contours of the histogram (micropore.wordpress.com/2011/11/15/…). Also take a look at this: matplotlib.org/examples/statistics/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.