[英]plotting histogram using matplotlib in python
I have a file containing 2 columns like: 我有一个包含2列的文件,例如:
111, 3
122, 4
155, 3
192, 5
11, 9
123, 10
120, 23
How can I be able to write the data like ((111,122,155,192,11,123,120),(3,4,3,5,9,10,23)) . 我怎么能写像((111,122,155,192,11,123,120),(3,4,3,5,9,10,23))这样的数据。 Now all I want to do is to plot it in a histogram using matplotlib
. 现在,我要做的就是使用matplotlib
将其绘制成直方图。
please help with some basic ideas. 请提供一些基本思路。 ! !
Do you mean something like this? 你的意思是这样吗?
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> xs, ys = np.loadtxt('/tmp/example.txt', delimiter=',').T
>>> print xs
[ 111. 122. 155. 192. 11. 122. 120.]
>>> print ys
[ 3. 4. 3. 5. 9. 10. 23.]
>>> plt.bar(xs, ys)
<Container object of 7 artists>
>>> plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.