Matplotlib-具有已合并数据的步进直方图 [英] Matplotlib - Stepped histogram with already binned data

查看:95
本文介绍了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-具有已合并数据的步进直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆