matplotlib stepfilled hist in y-log scale don't show correctly

旧时模样 提交于 2019-12-07 07:40:18

问题


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

Unfortunately I don't have the rights to post images, but you can check out this behaviour 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 figure shows correctly, whereas in the second case, with the option histtype='stepfilled' instead of 'bar', no. Somebody has any clue?


回答1:


It's an open bug in matplotlib. Maybe you can simulate the stepfilled manipulating the style of the bars in the first graphic.

The issue on github:

  • https://github.com/matplotlib/matplotlib/issues/196



回答2:


If you use

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

you get the expected result, with the caveat that it looks weird for bins with zero values.



来源:https://stackoverflow.com/questions/13583443/matplotlib-stepfilled-hist-in-y-log-scale-dont-show-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!