Re: [Matplotlib-users] Histograms

2011-09-29 Thread Michal
Stupid mistake, My data array was wrong I had it just to rotate and now it
is working.

On Thu, Sep 29, 2011 at 2:01 PM, Michal micta...@gmail.com wrote:

 Thank you for the links, but I had trouble to get them running with
 Matplotlib 1.0.1. However, I downloaded the source code from the Matplotlib
 book ( http://www.packtpub.com/support?nid=4110 ) and in chapter 9 is an
 example (7900_09_04_cvs.py) with work with csv files.

 I have tried to modify the original code, because my data is stored in
 dict. Please find below my problem code:

 import matplotlib.pyplot as plt
 import matplotlib.cm as cm
 import matplotlib.font_manager as font_manager


 types = sorted(cul_stat.keys()) #year
 print types = , types
 data_info = {}

 for type in types:
 for d in cul_stat[type]['Total'].data_info.keys():
 if d not in data_info:
 data_info[d] = 0

 data_info_all = sorted(data_info.keys())
 print data_info_all = , data_info_all #countries

 data = []
 for type in types:
 data_amount = []
 for d in data_info_all:
 try:
 data_amount.append(cul_stat[type]['Total'].data_info[d])
 except KeyError:
 data_amount.append(0)

 data.append(data_amount)
 print 'data = ',data

 # prepare the bottom array
 bottom = np.zeros(len(types))
 print bottom = , bottom
 width = .8
 # for each line in data
 for i in range(len(data)):
 # create the bars for each element, on top of the previous bars
 print , data[i], len(data[i])
 bt = plt.bar(range(len(data[i])), data[i], width=width,
  color=cm.hsv(32*(i)), label=data_info_all[i],
  bottom=bottom)
 # update the bottom array
 bottom += data[i]

 # label the X ticks with years
 plt.xticks(np.arange(len(types))+width/2, types)

 # some information on the plot
 plt.xlabel('Years')
 plt.ylabel('Population (in billions)')
 plt.title('World Population: 1950 - 2050 (predictions)')

 # draw a legend, with a smaller font
 plt.legend(loc='upper left',
prop=font_manager.FontProperties(size=7))

 plt.subplots_adjust(bottom=0.11, left=0.15)
 plt.savefig('7900_09_04.png')


 Output:
 +++

 types =  ['d1', 'd2', 'd3', 'd4', 'd5']
 data_info_all =  ['x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x9',
 'x10']
 data =  [[484, 1, 2, 1119, 3, 570, 314, 0, 1185, 420], [3236, 6, 4, 8099,
 8, 3833, 2285, 3, 8054, 3170], [1396, 6, 2, 3588, 5, 1450, , 3, 3478,
 1380], [492, 2, 1, 1257, 3, 528, 298, 2, 1240, 506], [21, 0, 0, 44, 1, 20,
 11, 0, 50, 17]]

 bottom =  [ 0.  0.  0.  0.  0.]
  [484, 1, 2, 1119, 3, 570, 314, 0, 1185, 420] 10
 Traceback (most recent call last):
   File snp_density.py, line 196, in module
 total_chr_overview(len_ref_seqs, cul_stat, args.chr)
   File snp_density.py, line 143, in total_chr_overview
 bottom=bottom)
   File
 /home/uqmlore1/apps/pymodules/lib/python2.7/site-packages/matplotlib/pyplot.py,
 line 1908, in bar
 ret = ax.bar(left, height, width, bottom, **kwargs)
   File
 /home/uqmlore1/apps/pymodules/lib/python2.7/site-packages/matplotlib/axes.py,
 line 4616, in bar
 nbars)
 AssertionError: incompatible sizes: argument 'bottom' must be length 10 or
 scalar
 +

 What did I wrong?

 Thank you in advance.



 On Wed, Sep 28, 2011 at 5:13 PM, Klonuo Umom klo...@gmail.com wrote:

 IMHO, when looking for basics and even more with intent to replicate some
 graph, it's easy to start by looking at matplotlib gallery:
 http://matplotlib.sourceforge.net/gallery.html and find best match.

 In you case:

 http://matplotlib.sourceforge.net/examples/pylab_examples/histogram_demo_extended.html
 http://matplotlib.sourceforge.net/examples/pylab_examples/table_demo.html

 for stacked bars, then look at code magic.

 I'm new user to matplotlib also, and was looking for easy way to create
 stacked bars some time ago, but unfortunately it's a bit more complicated
 than regular plot 'stuff'. I found gnuplot easier for stacked bars, but than
 as said my experience with matplotlib is basic


 Cheers


 On Wed, Sep 28, 2011 at 8:54 AM, Michal micta...@gmail.com wrote:

 Hello,
 I have found the following histogram example
 http://gnuplot.sourceforge.net/demo/histograms.4.png

 which was created with the following gnuplot code:
 http://gnuplot.sourceforge.net/demo/histograms.4.gnu

 and with this data set

 http://212.182.0.171/cgi-bin/dwww/usr/share/doc/gnuplot-doc/examples/immigration.dat

 How is it possible to do this with Matplotlib?

 Thank you in advance.




 --
 All the data continuously generated in your IT infrastructure contains a
 definitive record of customers, application performance, security
 threats, fraudulent activity and more. Splunk takes this data and makes
 sense of 

Re: [Matplotlib-users] Histograms

2011-09-28 Thread Klonuo Umom
IMHO, when looking for basics and even more with intent to replicate some
graph, it's easy to start by looking at matplotlib gallery:
http://matplotlib.sourceforge.net/gallery.html and find best match.

In you case:
http://matplotlib.sourceforge.net/examples/pylab_examples/histogram_demo_extended.html
http://matplotlib.sourceforge.net/examples/pylab_examples/table_demo.html

for stacked bars, then look at code magic.

I'm new user to matplotlib also, and was looking for easy way to create
stacked bars some time ago, but unfortunately it's a bit more complicated
than regular plot 'stuff'. I found gnuplot easier for stacked bars, but than
as said my experience with matplotlib is basic


Cheers


On Wed, Sep 28, 2011 at 8:54 AM, Michal micta...@gmail.com wrote:

 Hello,
 I have found the following histogram example
 http://gnuplot.sourceforge.net/demo/histograms.4.png

 which was created with the following gnuplot code:
 http://gnuplot.sourceforge.net/demo/histograms.4.gnu

 and with this data set

 http://212.182.0.171/cgi-bin/dwww/usr/share/doc/gnuplot-doc/examples/immigration.dat

 How is it possible to do this with Matplotlib?

 Thank you in advance.




 --
 All the data continuously generated in your IT infrastructure contains a
 definitive record of customers, application performance, security
 threats, fraudulent activity and more. Splunk takes this data and makes
 sense of it. Business sense. IT sense. Common sense.
 http://p.sf.net/sfu/splunk-d2dcopy1
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Histograms

2011-09-28 Thread Michal
Thank you for the links, but I had trouble to get them running with
Matplotlib 1.0.1. However, I downloaded the source code from the Matplotlib
book ( http://www.packtpub.com/support?nid=4110 ) and in chapter 9 is an
example (7900_09_04_cvs.py) with work with csv files.

I have tried to modify the original code, because my data is stored in dict.
Please find below my problem code:

import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.font_manager as font_manager


types = sorted(cul_stat.keys()) #year
print types = , types
data_info = {}

for type in types:
for d in cul_stat[type]['Total'].data_info.keys():
if d not in data_info:
data_info[d] = 0

data_info_all = sorted(data_info.keys())
print data_info_all = , data_info_all #countries

data = []
for type in types:
data_amount = []
for d in data_info_all:
try:
data_amount.append(cul_stat[type]['Total'].data_info[d])
except KeyError:
data_amount.append(0)

data.append(data_amount)
print 'data = ',data

# prepare the bottom array
bottom = np.zeros(len(types))
print bottom = , bottom
width = .8
# for each line in data
for i in range(len(data)):
# create the bars for each element, on top of the previous bars
print , data[i], len(data[i])
bt = plt.bar(range(len(data[i])), data[i], width=width,
 color=cm.hsv(32*(i)), label=data_info_all[i],
 bottom=bottom)
# update the bottom array
bottom += data[i]

# label the X ticks with years
plt.xticks(np.arange(len(types))+width/2, types)

# some information on the plot
plt.xlabel('Years')
plt.ylabel('Population (in billions)')
plt.title('World Population: 1950 - 2050 (predictions)')

# draw a legend, with a smaller font
plt.legend(loc='upper left',
   prop=font_manager.FontProperties(size=7))

plt.subplots_adjust(bottom=0.11, left=0.15)
plt.savefig('7900_09_04.png')


Output:
+++

types =  ['d1', 'd2', 'd3', 'd4', 'd5']
data_info_all =  ['x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x9',
'x10']
data =  [[484, 1, 2, 1119, 3, 570, 314, 0, 1185, 420], [3236, 6, 4, 8099, 8,
3833, 2285, 3, 8054, 3170], [1396, 6, 2, 3588, 5, 1450, , 3, 3478,
1380], [492, 2, 1, 1257, 3, 528, 298, 2, 1240, 506], [21, 0, 0, 44, 1, 20,
11, 0, 50, 17]]

bottom =  [ 0.  0.  0.  0.  0.]
 [484, 1, 2, 1119, 3, 570, 314, 0, 1185, 420] 10
Traceback (most recent call last):
  File snp_density.py, line 196, in module
total_chr_overview(len_ref_seqs, cul_stat, args.chr)
  File snp_density.py, line 143, in total_chr_overview
bottom=bottom)
  File
/home/uqmlore1/apps/pymodules/lib/python2.7/site-packages/matplotlib/pyplot.py,
line 1908, in bar
ret = ax.bar(left, height, width, bottom, **kwargs)
  File
/home/uqmlore1/apps/pymodules/lib/python2.7/site-packages/matplotlib/axes.py,
line 4616, in bar
nbars)
AssertionError: incompatible sizes: argument 'bottom' must be length 10 or
scalar
+

What did I wrong?

Thank you in advance.



On Wed, Sep 28, 2011 at 5:13 PM, Klonuo Umom klo...@gmail.com wrote:

 IMHO, when looking for basics and even more with intent to replicate some
 graph, it's easy to start by looking at matplotlib gallery:
 http://matplotlib.sourceforge.net/gallery.html and find best match.

 In you case:

 http://matplotlib.sourceforge.net/examples/pylab_examples/histogram_demo_extended.html
 http://matplotlib.sourceforge.net/examples/pylab_examples/table_demo.html

 for stacked bars, then look at code magic.

 I'm new user to matplotlib also, and was looking for easy way to create
 stacked bars some time ago, but unfortunately it's a bit more complicated
 than regular plot 'stuff'. I found gnuplot easier for stacked bars, but than
 as said my experience with matplotlib is basic


 Cheers


 On Wed, Sep 28, 2011 at 8:54 AM, Michal micta...@gmail.com wrote:

 Hello,
 I have found the following histogram example
 http://gnuplot.sourceforge.net/demo/histograms.4.png

 which was created with the following gnuplot code:
 http://gnuplot.sourceforge.net/demo/histograms.4.gnu

 and with this data set

 http://212.182.0.171/cgi-bin/dwww/usr/share/doc/gnuplot-doc/examples/immigration.dat

 How is it possible to do this with Matplotlib?

 Thank you in advance.




 --
 All the data continuously generated in your IT infrastructure contains a
 definitive record of customers, application performance, security
 threats, fraudulent activity and more. Splunk takes this data and makes
 sense of it. Business sense. IT sense. Common sense.
 http://p.sf.net/sfu/splunk-d2dcopy1
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 

Re: [Matplotlib-users] histograms : xmax

2009-07-09 Thread Sebastian Busch
hey there!



Pau wrote:
 ...
 0.00e+00   1.00e-04 81039
 1.00e-04   2.00e-04 4472
 2.00e-04   3.00e-04 2033
 ...
 
 The bins are given by the two first number columns.
 
 For instance, the first bin is from 0.00e+00 to 1.00e-04 and has the
 number of data 81039

hey pau!

i do not understand hist well myself, but i think it might be doing
something different from what you want. i think that if you run hist on
e.g. the numbers
100, 11, 10, 9, 0, 0, 0, 0, 0

and make 10 bins, it will give you

x   y
0   5
10  3
20  0
30  0
40  0
50  0
60  0
70  0
80  0
90  0
100 1

if you histogram the data on the y-axis, there is no reason why this
should be still connected to the x-axis.

you have already a histogramm -- if you want to rebin, i guess you
should use histogram on the x-axis and weight with the y-data.

 H = load ( './histo3.dat')
 h =  H[:, 2]  # the third column
 
 n, bins, patches = hist(h, 997, normed=0, log=0,
 facecolor='lightblue', alpha=0.75)

 0 - 9 -- on x axis
 Notice in the data file that x does not get further than 9.96e-02
 So the maximum should be 0.0996 and I am getting 9

if you pass only the third column to hist, it is a bit unfair to expect
it to know the other two ;)


good luck,
sebastian.



signature.asc
Description: OpenPGP digital signature
--
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] histograms ...

2009-07-05 Thread Sebastian Busch
Pau wrote:
 ...
 MODE: 0.00e+00 -  1.00e-04
 (2226):**
1: 1.00e-04 -  2.00e-04 ( 482):*
2: 2.00e-04 -  3.00e-04 ( 273):
3: 3.00e-04 -  4.00e-04 ( 173):
4: 4.00e-04 -  5.00e-04 ( 125):**
5: 5.00e-04 -  6.00e-04 (  99):*
6: 6.00e-04 -  7.00e-04 (  68):***
 ...
 I am supposed to show this plot tomorrow and I cannot figure out how
 to plot this with matplotlib
 ...

hey!

i'm not sure but maybe you are looking for something like this (will
crash on the text lines in the file -- you may want to add a try:...
except: pass around the split thing.



from scipy import *
from matplotlib.pyplot import *
from string import split

f = open(histo.dat)
data = f.readlines()
f.close()

x, y, dy = [], [], []
for i, line in enumerate(data):
x.append(i)
y.append(int(line.split('(')[1].split(')')[0]))
dy.append(sqrt(y[-1]))

bar(x, y, yerr=dy, align='center')
show()


good luck,
sebastian.



signature.asc
Description: OpenPGP digital signature
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] histograms ...

2009-07-05 Thread Pau
Hello!

thanks for the quick answer!

I have removed the text lines (do you mean the ones starting with a
hash, #? I removed those)

It complained about

from scipy import * # complained ImportError: No module named scipy

So I commented it out and added

from pylab import *

But it's crashing:

Traceback (most recent call last):
  File ./prova.py, line 14, in module
y.append(int(line.split('(')[1].split(')')[0]))
IndexError: list index out of range

where

hux(p2)| cat prova.py
#!/usr/bin/env python
from pylab import *
#from scipy import * # complained ImportError: No module named scipy
from matplotlib.pyplot import *
from string import split

f = open(histo2.dat)
data = f.readlines()
f.close()

x, y, dy = [], [], []
for i, line in enumerate(data):
   x.append(i)
   y.append(int(line.split('(')[1].split(')')[0]))
   dy.append(sqrt(y[-1]))

bar(x, y, yerr=dy, align='center')
show()

It would be great if I got this one done. Thanks for your help


Pau


2009/7/5 Sebastian Busch webmas...@thamnos.de:
 Pau wrote:
 ...
 MODE: 0.00e+00 -  1.00e-04
 (2226):**
    1: 1.00e-04 -  2.00e-04 ( 482):*
    2: 2.00e-04 -  3.00e-04 ( 273):
    3: 3.00e-04 -  4.00e-04 ( 173):
    4: 4.00e-04 -  5.00e-04 ( 125):**
    5: 5.00e-04 -  6.00e-04 (  99):*
    6: 6.00e-04 -  7.00e-04 (  68):***
 ...
 I am supposed to show this plot tomorrow and I cannot figure out how
 to plot this with matplotlib
 ...

 hey!

 i'm not sure but maybe you are looking for something like this (will
 crash on the text lines in the file -- you may want to add a try:...
 except: pass around the split thing.



 from scipy import *
 from matplotlib.pyplot import *
 from string import split

 f = open(histo.dat)
 data = f.readlines()
 f.close()

 x, y, dy = [], [], []
 for i, line in enumerate(data):
    x.append(i)
    y.append(int(line.split('(')[1].split(')')[0]))
    dy.append(sqrt(y[-1]))

 bar(x, y, yerr=dy, align='center')
 show()


 good luck,
 sebastian.





-- 
Let there be peace on earth. And let it begin with misc

--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] histograms ...

2009-07-05 Thread Pau
ok, I installed now scipy

Traceback (most recent call last):
  File ./prova.py, line 14, in module
y.append(int(line.split('(')[1].split(')')[0]))
IndexError: list index out of range

what is out of range?

sorry for the spamming... :(

2009/7/5 Pau vim.u...@googlemail.com:
 Hello!

 thanks for the quick answer!

 I have removed the text lines (do you mean the ones starting with a
 hash, #? I removed those)

 It complained about

 from scipy import * # complained ImportError: No module named scipy

 So I commented it out and added

 from pylab import *

 But it's crashing:

 Traceback (most recent call last):
  File ./prova.py, line 14, in module
    y.append(int(line.split('(')[1].split(')')[0]))
 IndexError: list index out of range

 where

 hux(p2)| cat prova.py
 #!/usr/bin/env python
 from pylab import *
 #from scipy import * # complained ImportError: No module named scipy
 from matplotlib.pyplot import *
 from string import split

 f = open(histo2.dat)
 data = f.readlines()
 f.close()

 x, y, dy = [], [], []
 for i, line in enumerate(data):
   x.append(i)
   y.append(int(line.split('(')[1].split(')')[0]))
   dy.append(sqrt(y[-1]))

 bar(x, y, yerr=dy, align='center')
 show()

 It would be great if I got this one done. Thanks for your help


 Pau


 2009/7/5 Sebastian Busch webmas...@thamnos.de:
 Pau wrote:
 ...
 MODE: 0.00e+00 -  1.00e-04
 (2226):**
    1: 1.00e-04 -  2.00e-04 ( 482):*
    2: 2.00e-04 -  3.00e-04 ( 273):
    3: 3.00e-04 -  4.00e-04 ( 173):
    4: 4.00e-04 -  5.00e-04 ( 125):**
    5: 5.00e-04 -  6.00e-04 (  99):*
    6: 6.00e-04 -  7.00e-04 (  68):***
 ...
 I am supposed to show this plot tomorrow and I cannot figure out how
 to plot this with matplotlib
 ...

 hey!

 i'm not sure but maybe you are looking for something like this (will
 crash on the text lines in the file -- you may want to add a try:...
 except: pass around the split thing.



 from scipy import *
 from matplotlib.pyplot import *
 from string import split

 f = open(histo.dat)
 data = f.readlines()
 f.close()

 x, y, dy = [], [], []
 for i, line in enumerate(data):
    x.append(i)
    y.append(int(line.split('(')[1].split(')')[0]))
    dy.append(sqrt(y[-1]))

 bar(x, y, yerr=dy, align='center')
 show()


 good luck,
 sebastian.





 --
 Let there be peace on earth. And let it begin with misc




-- 
Let there be peace on earth. And let it begin with misc

--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] histograms ...

2009-07-05 Thread Gökhan SEVER
On Sun, Jul 5, 2009 at 3:41 PM, Pau vim.u...@googlemail.com wrote:

 ok, I installed now scipy

 Traceback (most recent call last):
  File ./prova.py, line 14, in module
y.append(int(line.split('(')[1].split(')')[0]))
 IndexError: list index out of range

 what is out of range?

 sorry for the spamming... :(

 2009/7/5 Pau vim.u...@googlemail.com:
  Hello!
 
  thanks for the quick answer!
 
  I have removed the text lines (do you mean the ones starting with a
  hash, #? I removed those)
 
  It complained about
 
  from scipy import * # complained ImportError: No module named scipy
 
  So I commented it out and added
 
  from pylab import *
 
  But it's crashing:
 
  Traceback (most recent call last):
   File ./prova.py, line 14, in module
 y.append(int(line.split('(')[1].split(')')[0]))
  IndexError: list index out of range
 
  where
 
  hux(p2)| cat prova.py
  #!/usr/bin/env python
  from pylab import *
  #from scipy import * # complained ImportError: No module named scipy
  from matplotlib.pyplot import *
  from string import split
 
  f = open(histo2.dat)
  data = f.readlines()
  f.close()
 
  x, y, dy = [], [], []
  for i, line in enumerate(data):
x.append(i)
y.append(int(line.split('(')[1].split(')')[0]))
dy.append(sqrt(y[-1]))
 
  bar(x, y, yerr=dy, align='center')
  show()
 
  It would be great if I got this one done. Thanks for your help
 
 
  Pau
 
 
  2009/7/5 Sebastian Busch webmas...@thamnos.de:
  Pau wrote:
  ...
  MODE: 0.00e+00 -  1.00e-04
 
 (2226):**
 1: 1.00e-04 -  2.00e-04 ( 482):*
 2: 2.00e-04 -  3.00e-04 ( 273):
 3: 3.00e-04 -  4.00e-04 ( 173):
 4: 4.00e-04 -  5.00e-04 ( 125):**
 5: 5.00e-04 -  6.00e-04 (  99):*
 6: 6.00e-04 -  7.00e-04 (  68):***
  ...
  I am supposed to show this plot tomorrow and I cannot figure out how
  to plot this with matplotlib
  ...
 
  hey!
 
  i'm not sure but maybe you are looking for something like this (will
  crash on the text lines in the file -- you may want to add a try:...
  except: pass around the split thing.
 
 
 
  from scipy import *
  from matplotlib.pyplot import *
  from string import split
 
  f = open(histo.dat)
  data = f.readlines()
  f.close()
 
  x, y, dy = [], [], []
  for i, line in enumerate(data):
 x.append(i)
 y.append(int(line.split('(')[1].split(')')[0]))
 dy.append(sqrt(y[-1]))
 
  bar(x, y, yerr=dy, align='center')
  show()
 
 
  good luck,
  sebastian.
 
 
 
 
 
  --
  Let there be peace on earth. And let it begin with misc
 



 --
 Let there be peace on earth. And let it begin with misc


 --
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Pau,

I recommend you to run this script via ipython.

First install it if you haven't and and run your script with %run magic
command. There you will be able to easily pinpoint the index out of range
error.

-- 
Gökhan
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] histograms ...

2009-07-05 Thread Pau
Hello,

thanks, yes, I had done this already. It's pointing to the append
place for y, but I am absolutely lost at that line. I don't understand
it.

I guess this has to do with the format of the data (see previous e-mail)

--- 13y.append(int(line.split('(')[1].split(')')[0]))

anyway... thanks for all... I guess that the last minute panic is not
exactly the best strategy, as usual

Pau

2009/7/5 Gökhan SEVER gokhanse...@gmail.com:
 On Sun, Jul 5, 2009 at 3:41 PM, Pau vim.u...@googlemail.com wrote:

 ok, I installed now scipy

 Traceback (most recent call last):
  File ./prova.py, line 14, in module
    y.append(int(line.split('(')[1].split(')')[0]))
 IndexError: list index out of range

 what is out of range?

 sorry for the spamming... :(

 2009/7/5 Pau vim.u...@googlemail.com:
  Hello!
 
  thanks for the quick answer!
 
  I have removed the text lines (do you mean the ones starting with a
  hash, #? I removed those)
 
  It complained about
 
  from scipy import * # complained ImportError: No module named scipy
 
  So I commented it out and added
 
  from pylab import *
 
  But it's crashing:
 
  Traceback (most recent call last):
   File ./prova.py, line 14, in module
     y.append(int(line.split('(')[1].split(')')[0]))
  IndexError: list index out of range
 
  where
 
  hux(p2)| cat prova.py
  #!/usr/bin/env python
  from pylab import *
  #from scipy import * # complained ImportError: No module named scipy
  from matplotlib.pyplot import *
  from string import split
 
  f = open(histo2.dat)
  data = f.readlines()
  f.close()
 
  x, y, dy = [], [], []
  for i, line in enumerate(data):
    x.append(i)
    y.append(int(line.split('(')[1].split(')')[0]))
    dy.append(sqrt(y[-1]))
 
  bar(x, y, yerr=dy, align='center')
  show()
 
  It would be great if I got this one done. Thanks for your help
 
 
  Pau
 
 
  2009/7/5 Sebastian Busch webmas...@thamnos.de:
  Pau wrote:
  ...
  MODE: 0.00e+00 -  1.00e-04
 
  (2226):**
     1: 1.00e-04 -  2.00e-04 ( 482):*
     2: 2.00e-04 -  3.00e-04 ( 273):
     3: 3.00e-04 -  4.00e-04 ( 173):
     4: 4.00e-04 -  5.00e-04 ( 125):**
     5: 5.00e-04 -  6.00e-04 (  99):*
     6: 6.00e-04 -  7.00e-04 (  68):***
  ...
  I am supposed to show this plot tomorrow and I cannot figure out how
  to plot this with matplotlib
  ...
 
  hey!
 
  i'm not sure but maybe you are looking for something like this (will
  crash on the text lines in the file -- you may want to add a try:...
  except: pass around the split thing.
 
 
 
  from scipy import *
  from matplotlib.pyplot import *
  from string import split
 
  f = open(histo.dat)
  data = f.readlines()
  f.close()
 
  x, y, dy = [], [], []
  for i, line in enumerate(data):
     x.append(i)
     y.append(int(line.split('(')[1].split(')')[0]))
     dy.append(sqrt(y[-1]))
 
  bar(x, y, yerr=dy, align='center')
  show()
 
 
  good luck,
  sebastian.
 
 
 
 
 
  --
  Let there be peace on earth. And let it begin with misc
 



 --
 Let there be peace on earth. And let it begin with misc


 --
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users

 Pau,

 I recommend you to run this script via ipython.

 First install it if you haven't and and run your script with %run magic
 command. There you will be able to easily pinpoint the index out of range
 error.

 --
 Gökhan




-- 
Let there be peace on earth. And let it begin with misc

--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] histograms ...

2009-07-05 Thread Gökhan SEVER
OK, You are one step closer to point out the error.

Look for an instance of line. What does it output?

Then try fiddling with the split() function and proper indexes.

Haha, are you a Mediterranean person or what?


On Sun, Jul 5, 2009 at 3:54 PM, Pau vim.u...@googlemail.com wrote:

 Hello,

 thanks, yes, I had done this already. It's pointing to the append
 place for y, but I am absolutely lost at that line. I don't understand
 it.

 I guess this has to do with the format of the data (see previous e-mail)

 --- 13y.append(int(line.split('(')[1].split(')')[0]))

 anyway... thanks for all... I guess that the last minute panic is not
 exactly the best strategy, as usual

 Pau

 2009/7/5 Gökhan SEVER gokhanse...@gmail.com:
  On Sun, Jul 5, 2009 at 3:41 PM, Pau vim.u...@googlemail.com wrote:
 
  ok, I installed now scipy
 
  Traceback (most recent call last):
   File ./prova.py, line 14, in module
 y.append(int(line.split('(')[1].split(')')[0]))
  IndexError: list index out of range
 
  what is out of range?
 
  sorry for the spamming... :(
 
  2009/7/5 Pau vim.u...@googlemail.com:
   Hello!
  
   thanks for the quick answer!
  
   I have removed the text lines (do you mean the ones starting with a
   hash, #? I removed those)
  
   It complained about
  
   from scipy import * # complained ImportError: No module named scipy
  
   So I commented it out and added
  
   from pylab import *
  
   But it's crashing:
  
   Traceback (most recent call last):
File ./prova.py, line 14, in module
  y.append(int(line.split('(')[1].split(')')[0]))
   IndexError: list index out of range
  
   where
  
   hux(p2)| cat prova.py
   #!/usr/bin/env python
   from pylab import *
   #from scipy import * # complained ImportError: No module named scipy
   from matplotlib.pyplot import *
   from string import split
  
   f = open(histo2.dat)
   data = f.readlines()
   f.close()
  
   x, y, dy = [], [], []
   for i, line in enumerate(data):
 x.append(i)
 y.append(int(line.split('(')[1].split(')')[0]))
 dy.append(sqrt(y[-1]))
  
   bar(x, y, yerr=dy, align='center')
   show()
  
   It would be great if I got this one done. Thanks for your help
  
  
   Pau
  
  
   2009/7/5 Sebastian Busch webmas...@thamnos.de:
   Pau wrote:
   ...
   MODE: 0.00e+00 -  1.00e-04
  
  
 (2226):**
  1: 1.00e-04 -  2.00e-04 ( 482):*
  2: 2.00e-04 -  3.00e-04 ( 273):
  3: 3.00e-04 -  4.00e-04 ( 173):
  4: 4.00e-04 -  5.00e-04 ( 125):**
  5: 5.00e-04 -  6.00e-04 (  99):*
  6: 6.00e-04 -  7.00e-04 (  68):***
   ...
   I am supposed to show this plot tomorrow and I cannot figure out how
   to plot this with matplotlib
   ...
  
   hey!
  
   i'm not sure but maybe you are looking for something like this (will
   crash on the text lines in the file -- you may want to add a try:...
   except: pass around the split thing.
  
  
  
   from scipy import *
   from matplotlib.pyplot import *
   from string import split
  
   f = open(histo.dat)
   data = f.readlines()
   f.close()
  
   x, y, dy = [], [], []
   for i, line in enumerate(data):
  x.append(i)
  y.append(int(line.split('(')[1].split(')')[0]))
  dy.append(sqrt(y[-1]))
  
   bar(x, y, yerr=dy, align='center')
   show()
  
  
   good luck,
   sebastian.
  
  
  
  
  
   --
   Let there be peace on earth. And let it begin with misc
  
 
 
 
  --
  Let there be peace on earth. And let it begin with misc
 
 
 
 --
  ___
  Matplotlib-users mailing list
  Matplotlib-users@lists.sourceforge.net
  https://lists.sourceforge.net/lists/listinfo/matplotlib-users
 
  Pau,
 
  I recommend you to run this script via ipython.
 
  First install it if you haven't and and run your script with %run magic
  command. There you will be able to easily pinpoint the index out of range
  error.
 
  --
  Gökhan
 



 --
 Let there be peace on earth. And let it begin with misc




-- 
Gökhan
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] histograms ...

2009-07-05 Thread Sebastian Busch
Pau wrote:
 ...
 2009/7/5 Gökhan SEVER gokhanse...@gmail.com:
 On Sun, Jul 5, 2009 at 3:41 PM, Pau vim.u...@googlemail.com wrote:
 ...
 Traceback (most recent call last):
  File ./prova.py, line 14, in module
y.append(int(line.split('(')[1].split(')')[0]))
 IndexError: list index out of range
 2009/7/5 Sebastian Busch webmas...@thamnos.de:
 Pau wrote:
 (2226):**
1: 1.00e-04 -  2.00e-04 ( 482):*

hey there,

what the line should do is to get the number out of the lengthy text. it
 should take what is behind a ( and before a ). my guess is that in
some line of your textfile, there is no bracket. give this a try:

from scipy import *
from matplotlib.pyplot import *
from string import split

f = open(histo.dat)
data = f.readlines()
f.close()

x, y, dy = [], [], []
for i, line in enumerate(data):
try:
x.append(i)
y.append(int(line.split('(')[1].split(')')[0]))
dy.append(sqrt(y[-1]))
except:
pass

bar(x, y, yerr=dy, align='center')
show()



which will skip any error. but check if your data made it into y or
were skipped as well! ;)

best,
sebastian.



signature.asc
Description: OpenPGP digital signature
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] histograms ...

2009-07-05 Thread Sebastian Busch
 Pau wrote:
 ...
 MODE: 0.00e+00 -  1.00e-04

 (2226):**
1: 1.00e-04 -  2.00e-04 ( 482):*
2: 2.00e-04 -  3.00e-04 ( 273):
3: 3.00e-04 -  4.00e-04 ( 173):
4: 4.00e-04 -  5.00e-04 ( 125):**
5: 5.00e-04 -  6.00e-04 (  99):*
6: 6.00e-04 -  7.00e-04 (  68):***
 ...

i think it was the last (empty) line which was messing up things. the
following works (at least here.)


from scipy import *
from matplotlib.pyplot import *
from string import split

f = open(histo2.dat)
data = f.readlines()
f.close()

x, y, dy = [], [], []
for i, line in enumerate(data):
try:
y.append(int(line.split('(')[1].split(')')[0]))
x.append(i)
dy.append(sqrt(y[-1]))
except:
pass

bar(x, y, yerr=dy, align='center')
show()



main difference is swapping of x and y append(..): if something goes
wrong width y, it won't do x and therefore both will have the same
length in the end (i think it was complaining about the two not having
the same length).


as a side note:
you might want to use

yscale('log')
and / or
xscale('log')

as your data drop pretty fast.



good luck  good night,
sebastian.



signature.asc
Description: OpenPGP digital signature
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] histograms

2006-12-16 Thread Eric Firing
Simson,

Using your example I get most of the values around 0.5, and the ends 
near 2.3.  This is correct for a probability density function; the 
integral of the pdf over the range of the bins should be 1.  This way 
the pdf values as a function of x don't change with changes in the 
number of bins, apart from the change in resolution.  The probability of 
a datum appearing in any subrange is the integral of the pdf over that 
subrange.

Having the sum of the bars add to 1 would be a different sort of 
normalization.  Undoubtedly it has a name, but I don't know what it is. 
And I don't know why you were getting a y-axis up to 7.

Eric

Simson Garfinkel wrote:
 I'm plotting some histograms with hist()  --- well, actually with  
 ax.hist(), where ax is an axis --- and the normed=1 isn't working  
 the way I would expect.
 
 from pylab import *
 
 data = sin(arange(0.0,100,.01))
 
 fig = figure()
 ax  = fig.add_subplot(111)
 ax.hist(data,bins=50,normed=1,align='center')
 show()
 
 If I do not include normed=1, then the Y scale is an actual count  
 inside each bin. (The scale goes from 1-1000).
 
 If I include normed=1, the Y scale goes from  1 - 7.  What does that  
 mean?  normed is supposed to make the first result from ax.hist be a  
 normalized probability distribution. But I would think that it would  
 change the Y axis to be a probability as well, and it doesn't do that.
 
 The docstrings do not give any insight, so I looked at the source  
 code. It certainly *looks* like it's plotting the probability  
 distribution. But why does the above example give a Y scale going  
 from 1 to 7? Perhaps I'm showing my lack of statistics here, but I  
 would think that a strict probability distribution would have the  
 value of all of the bars adding to 1,
 
 Sorry to send out so many messages today. I really am trying to  
 figure this out on my own...
 
 
 
 
 
 -
 Take Surveys. Earn Cash. Influence the Future of IT
 Join SourceForge.net's Techsay panel and you'll get the chance to share your
 opinions on IT  business topics through brief surveys - and earn cash
 http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users