Matplotlib stepfilled hist in y-log scale not showing correctly

I have a problem displaying histograms in matplotlib when both histtype = 'stepfilled' and log = True options are used. I had this problem in matplotlib version 1.1.0 and I found that it is still present in version 1.2.0.

Unfortunately, I do not have permission to post images, but you can check this behavior with this simple code:

import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt mu, sigma = 200, 25 x = mu + sigma*np.random.randn(10000) n, bins, patches = plt.hist(x, 50, normed=1, histtype='bar',log=True) plt.savefig("test1.png") plt.clf() n, bins, patches = plt.hist(x, 50, normed=1, histtype='stepfilled',log=True) plt.savefig("test2.png") 

The first digit is displayed correctly, while in the second case with the option histtype = 'stepfilled' instead of "bar" no. Does anyone have a key?

+4
source share
2 answers

This is an open bug in matplotlib. Perhaps you can simulate stepfilled by controlling the style of the bars in the first chart.

Question about github:

+1
source

If you use

 plt.hist(x, 50, normed=1, histtype='stepfilled') plt.semilogy() 

You will get the expected result, with the caveat that it looks strange for mailboxes with zero values.

+1
source

Source: https://habr.com/ru/post/1240977/


All Articles