 # display data in histogram

hi all,
I am working on some graph stuffs and stuck at a point.
I am trying to plot a histogram using simple :
import matplotlib.pyplot as plt
.
.
plt.hist(x,bins=10,histtype=‘bar’)
plt.show

but i want to know
1)
what is the value of a particular bar in histogram and also want to
print in on output image along with the bars ( either at top of bar or
at bottom)2) How to give input of 2 types of dataset in
single hist() command , so that i can compare 2 different dataset side
by side on my output image. ( i dont want it on top of each other as
given by the command histtype: [ ‘barstacked’] and also i read some example in matplotlib site, but they are for random numbers : something like this:

``````x0 = mu + sigma*P.randn(10000)

x1 = mu + sigma*P.randn(7000)

x2 = mu + sigma*P.randn(3000)

P.figure()
n, bins, patches = P.hist( [x0,x1,x2], 10, histtype='bar')
``````

but i need this comparision for some dataset.

thanx

ankita

Hi ankita,

hi all,

I am working on some graph stuffs and stuck at a point.

I am trying to plot a histogram using simple :

*import matplotlib.pyplot as plt
.
.
plt.hist(x,bins=10,histtype='bar')

plt.show()

*
but i want to know

1) what is the value of a particular bar in histogram and also want to
print in on output image along with the bars ( either at top of bar or at
bottom)*

n, bins, patches = plt.hist(...)
gives you the bin-egdes 'bins' the corresponding frequency / number of values
per bin 'n' and the mpl-objects of the shown bars

# e.g. for top of the bar:
n, bins, patches = plt.hist(x0, bins=10, histtype='bar')
for index in xrange(len(bins)-1):
plt.text(bins[index], n[index], " %i " % (n[index]))

*2) How to give input of 2 types of dataset in single hist() command , so
that i can compare 2 different dataset side by side on my output image. ( i
dont want it on top of each other as given by the command *histtype*:
[ ‘barstacked’] and also i read some example in matplotlib site, but
they are for random numbers : something like this:

x0 = mu + sigma*P.randn(10000)
x1 = mu + sigma*P.randn(7000)
x2 = mu + sigma*P.randn(3000)
P.figure()
n, bins, patches = P.hist( [x0,x1,x2], 10, histtype='bar')

but i need this comparision for some dataset.

I can't see any problems with placing dataset instead of x0 and x1 into this
call.
Please notice: in that case n is a tuple and each tuple-element corresponds to
the number of values per bin of one dataset.

Kind regards Matthias

···

On Wednesday 04 November 2009 06:04:55 ankita dutta wrote: