简体   繁体   English

来自已经分箱的数据的直方图,我有分箱和频率值

[英]Histogram from data which is already binned, I have bins and frequency values

All the matplotlib examples with hist() generate a data set, provide the data set to the hist function with some bins (possibly non-uniformly spaced) and the function automatically calculates and then plots the histogram.所有带有hist()的 matplotlib 示例生成一个数据集,将数据集提供给带有一些 bin(可能是非均匀间隔)的hist函数,该函数会自动计算并绘制直方图。

I already have histogram data and I simply want to plot it, how can I do that?!我已经有了直方图数据,我只想绘制它,我该怎么做?! For example, I have the bins (half open ranges are denoted by the square and curved bracket notation),例如,我有箱子(半开范围用方括号和弧形括号表示法表示),

[0, 1)   0
[1, 2)   3
[2, 3)   8
[3, 4)   6
[4, 5)   2
[5, 6)   3
[6, 7)   1
[7, 8)   0

Perhaps the weight parameter would be of help in your problem.也许权重参数对您的问题有帮助。

import matplotlib.pyplot as plt

a= [1,2,3,4,5,6,7,8,9]
b= [5,3,4,5,3,2,1,2,3]
plt.hist(a,9, weights=b)
plt.show()

Or, as tcaswell said, you could just make a bar plot and change the x-axis.或者,正如 tcaswell 所说,您可以制作条形图并更改 x 轴。

Using matplotlib how could I plot a histogram with given data in python 使用 matplotlib 我怎么能用python中的给定数据绘制直方图

Is a link.是链接。

Also, as an alternative (similar to Matlab), you can use bar :此外,作为替代方案(类似于 Matlab),您可以使用bar

import matplotlib.pyplot as plt

a= [1,2,3,4,5,6,7,8,9]
b= [5,3,4,5,3,2,1,2,3]
plt.bar(a,b)

在此处输入图片说明

Then, you can also add the title and other stuff and, finally, save the image:然后,您还可以添加标题和其他内容,最后保存图像:

plt.title("Clock cycles")
plt.grid()
plt.xlabel("Size of the matrices processed")
plt.ylabel("Clock cycles")
plt.savefig("clock_cycles.svg")

I'm surprised nobody mentioned plt.step here yet for making step plots...我很惊讶没有人在这里提到 plt.step 来制作阶梯图......

a= [1,2,3,4,5,6,7,8,9]
b= [5,3,4,5,3,2,1,2,3]
plt.step(a,b)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM