diffracteD
diffracteD

Reputation: 758

plotting histogram using matplotlib in python

I have a file containing 2 columns like:

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)) . Now all I want to do is to plot it in a histogram using matplotlib.
please help with some basic ideas. !

Upvotes: 0

Views: 3501

Answers (1)

wim
wim

Reputation: 362478

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()

enter image description here

Upvotes: 5

Related Questions