如何仅使用对数xscale在pyplot中绘制累积直方图

时间:2012-12-15 03:55:21

标签: python matplotlib

这绘制了对数xscale和yscale。似乎无法弄清楚如何仅绘制对数xscale。

plt.hist(data, bins=10, cumulative=True, log=True)

1 个答案:

答案 0 :(得分:2)

您可以使用以下内容更改y轴中的日志:

plt.gca().set_yscale('linear')

当图形清晰时,按L键。

但是,hist()log=True的{​​{1}}不会绘制对数x轴。来自docs

  

matplotlib.pyplot.hist(x,bins = 10,...)

     

箱:      一个整数个箱或一个给出箱子的序列。如果bin是一个整数,将返回bin + 1 bin边缘,与numpy.histogram()的numpy版本> = 1.3一致,并且在早期版本中使用new = True参数。 如果垃圾箱是序列,则支持不等间距的垃圾箱。

因此,如果您只设置bins=10它们将是等间距的,这就是为什么当您将xscale设置为log时它们的宽度递减。要在log xscale中获得等间距的bin,您需要以下内容:

plt.hist(x, bins=10**np.linspace(0, 1, 10))
相关问题