本文介绍了Matplotlib - 已分箱数据的阶梯直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用已经分箱的数据获取直方图.我一直在尝试为此使用 bar(),但我似乎无法弄清楚如何使其成为阶梯直方图 就像示例中的这个,而不是填充的直方图.

I am trying to get a histogram with already binned data. I have been trying to use bar() for this, but I can't seem to figure out how to make it a stepped histogram like this one from the examples, instead of a filled histogram.

推荐答案

你可能会作弊,通过偏移你的数据并使用 plot 代替:

You could cheat, by offsetting your data and using plot instead:

from matplotlib import pyplot
import numpy as np

#sample data:
x = np.arange(30)
y = np.cumsum(np.arange(30))
#offset the x for horizontal, repeat the y for vertical:
x = np.ravel(zip(x,x+1))
y = np.ravel(zip(y,y))

pyplot.plot(x,y)
pyplot.savefig('plt.png')

剧情:

这篇关于Matplotlib - 已分箱数据的阶梯直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 07:44
查看更多