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  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] Using labels with "twinx()"

2011-09-28 Thread Stephen George

On 28/09/2011 4:32 PM, Klonuo Umom wrote:

Please consider:

plot([1, 2, 3, 4], label='line 1')
twinx()
plot([11, 12, 11, 14], label='line 2')
legend()


will draw only label for 'line 2'

plot([1, 2, 3, 4], label='line 1')
legend()
twinx()
plot([11, 12, 11, 14], label='line 2')
legend()


same result, as it will overwrite label 'line 1' with label 'line 2'

How to deal with this, without manually positioning legends and if 
possible including all annotated plot lines in one legend?



Thanks



I would do something like

   from matplotlib import pylab

   LegendText = []

   pylab.twinx() # << had to move before first plot else it blew up

   pylab.plot([1, 2, 3, 4] )
   LegendText.append('line 1')

   pylab.plot([11, 12, 11, 14])
   LegendText.append('line 2')

   pylab.legend( LegendText , loc='lower right')

   pylab.show()


Don't know if there is a better way
Steve
--
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] Using labels with "twinx()"

2011-09-28 Thread Benjamin Root
On Wednesday, September 28, 2011, Klonuo Umom  wrote:
> Please consider:
>
> plot([1, 2, 3, 4], label='line 1')
> twinx()
> plot([11, 12, 11, 14], label='line 2')
> legend()
>
> will draw only label for 'line 2'
>
> plot([1, 2, 3, 4], label='line 1')
> legend()
> twinx()
> plot([11, 12, 11, 14], label='line 2')
> legend()
>
> same result, as it will overwrite label 'line 1' with label 'line 2'
> How to deal with this, without manually positioning legends and if
possible including all annotated plot lines in one legend?
>
> Thanks

Could you file a bug report on this on github?  Unfortunately, I think the
problem is going to be fairly complicated to solve.

Thanks!
Ben Root
--
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] Fw: matplotlib - fill open path inside U.S. borders + sample map

2011-09-28 Thread Jeff Whitaker

On 9/27/11 5:37 PM, Jeff Whitaker wrote:

On 9/27/11 4:57 PM, Isidora wrote:

The attached map shows plotted fill paths whose filling extends only to the 
U.S. borders.  Is there any way I could accomplish something like it using 
Basemap?

Thanks

Isidora:

It's probably possible, but there's no simple recipe.  The 
drawcoastlines method returns a LineCollection which you should be 
able to use to do what you want.  Sorry I can't be more specific, but 
I don't have time to go into any more depth right now.


-Jeff


Isidora:  Another option would be to create a gridded field defining the 
area you would like to enclose, use contourf to draw the boundaries of 
the region, then mask out the ocean areas with the maskoceans function.


-Jeff

-- Forwarded Message --
From: "Isidora"  
To:matplotlib-users@lists.sourceforge.net  

Subject: matplotlib - fill open path inside U.S. borders
Date: Mon, 26 Sep 2011 19:55:49 GMT

Hi,
I am trying to plot filled paths over a U.S. map.  I plot the given paths, but 
since these are not closed paths, the filling is truncated at a line drawn 
between last and first point in the path.  I want to extend the path to the 
United States border instead.


I am no expert in matplotlib or GIS.  Could anyone help me find documentation 
or blogs discussing this type of issue? I am convinced somebody else has 
already faced this problem although I have not been able to find any paper, 
documentation, blog on it.

Thank you


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


--
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] Using labels with "twinx()"

2011-09-28 Thread Jae-Joon Lee
On Wed, Sep 28, 2011 at 3:32 PM, Klonuo Umom  wrote:
> How to deal with this, without manually positioning legends and if possible
> including all annotated plot lines in one legend?

*twinx* creates a new axes. Thus there are TWO axes, and you need to
do some manual adjustment. I believe that the solution suggested by
Stephen George is essentially the best way, although you may try to
tweak things using the Axes.get_legend_handles_labels method (
http://matplotlib.sourceforge.net/users/legend_guide.html#what-to-be-displayed
).

Alternatively, you can try the axes_grid1 toolkit which automatically
merges legends for you. Check out the example below.

http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html#example-1-twinx

Regards,

-JJ

--
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] Fw: matplotlib - fill open path inside U.S. borders + sample map

2011-09-28 Thread Filipe Pires Alvarenga Fernandes
Hi Isidora, in the past I used the matlab function below for a similar
task. Maybe it can be adapted to your problem. If you can provide a
small sample of your problem I can try to implement that in python (it
has been in my TODO list for a while, but i cannot promise.)

http://woodshole.er.usgs.gov/operations/sea-mat/mapstuff-html/join_cst.m

-Filipe

On Wed, Sep 28, 2011 at 09:39, Jeff Whitaker  wrote:
> On 9/27/11 5:37 PM, Jeff Whitaker wrote:
>
> On 9/27/11 4:57 PM, Isidora wrote:
>
> The attached map shows plotted fill paths whose filling extends only to the
> U.S. borders.  Is there any way I could accomplish something like it using
> Basemap?
>
> Thanks
>
> Isidora:
>
> It's probably possible, but there's no simple recipe.  The drawcoastlines
> method returns a LineCollection which you should be able to use to do what
> you want.  Sorry I can't be more specific, but I don't have time to go into
> any more depth right now.
>
> -Jeff
>
> Isidora:  Another option would be to create a gridded field defining the
> area you would like to enclose, use contourf to draw the boundaries of the
> region, then mask out the ocean areas with the maskoceans function.
>
> -Jeff
>
> -- Forwarded Message --
> From: "Isidora" 
> To: matplotlib-users@lists.sourceforge.net
> Subject: matplotlib - fill open path inside U.S. borders
> Date: Mon, 26 Sep 2011 19:55:49 GMT
>
> Hi,
> I am trying to plot filled paths over a U.S. map.  I plot the given paths,
> but since these are not closed paths, the filling is truncated at a line
> drawn between last and first point in the path.  I want to extend the path
> to the United States border instead.
>
>
> I am no expert in matplotlib or GIS.  Could anyone help me find
> documentation or blogs discussing this type of issue? I am convinced
> somebody else has already faced this problem although I have not been able
> to find any paper, documentation, blog on it.
>
> Thank you
>
>
> --
> 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
>
>
> --
> 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] PDF/SVG Backends Don't Save FigureImages

2011-09-28 Thread Dave Hirschfeld
Michael Droettboom  writes:

> 
> > the PDF image :/
> Can you send the PDF file to me (off-list)?  It would be helpful to look 
> at the content of the file and see the nature of the failure.
> 
> Mike
> 

Done! Let me know if it doesn't arrive...

-Dave



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


[Matplotlib-users] matplotlib - fill open path inside U.S. borders + sample map

2011-09-28 Thread Isidora
Hi Filipe,

I have just seen your answers.  I am trying to plot on a background GIF map, 
lines like the ones you can see in 
http://www.spc.noaa.gov/products/outlook/day1probotlk_2000_wind.gif.  I can 
plot the lines as  you see them in this link without a problem.  However, 
because those lines are not closed polygons, the filling extends only to a 
straight line between first and last point of the curve. 
I want the filling to extend all the way to the border of United States.

Since drawcountries() return a Collection of paths without any metadata 
identifying the country/countries been separated by it, I cannot use it to mask 
the area outside ofthe borders out.  

I'd appreciate any link/documentation I could read to help me resolve this 
issue.

Thank you


--
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] matplotlib - fill open path inside U.S. borders + sample map

2011-09-28 Thread Jeff Whitaker
On 9/28/11 2:19 PM, Isidora wrote:
> Hi Filipe,
>
> I have just seen your answers.  I am trying to plot on a background GIF map, 
> lines like the ones you can see in 
> http://www.spc.noaa.gov/products/outlook/day1probotlk_2000_wind.gif.  I can 
> plot the lines as  you see them in this link without a problem.  However, 
> because those lines are not closed polygons, the filling extends only to a 
> straight line between first and last point of the curve.
> I want the filling to extend all the way to the border of United States.
>
> Since drawcountries() return a Collection of paths without any metadata 
> identifying the country/countries been separated by it, I cannot use it to 
> mask the area outside ofthe borders out.
>
> I'd appreciate any link/documentation I could read to help me resolve this 
> issue.
>
> Thank you
Isidora

Nobody has tried to do this (that I know of), so I can't point you to 
anything specific.  Did you see my message about creating a gridded 
field (say 1's for points inside and 0's for points outside the region), 
the calling contour to draw the line?  You can use the is_land method to 
determine if a point is over land or not, but there is not way to 
determine whether a given point is inside a country.  As you found out, 
there is no metadata associated with the coastlines or political 
boundary lines.

The fillcontinents method returns a list matplotlib polygon instances 
that represent the land areas.  One of them is North America, and could 
be used to clip your line segments - but there is no easy way to 
determine which one it is.

If you can find a shapefile that just contains a CONUS polygon, you 
could use that I suppose.

-Jeff

-- 
Jeffrey S. Whitaker Phone  : (303)497-6313
Meteorologist   FAX: (303)497-6449
NOAA/OAR/PSD  R/PSD1Email  : jeffrey.s.whita...@noaa.gov
325 BroadwayOffice : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web: http://tinyurl.com/5telg


--
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] Using labels with "twinx()"

2011-09-28 Thread Klonuo Umom
Thanks Stephen, but I'm not sure if I follow correctly: I used `twinx()` as
I wanted "line 1" to be referenced on left Y-axis and "line 2" on right
Y-axis. In your example I can't see what's the purpose of twinx() command? -
It presents left Y-axis as default 0 to 1 values not referenced to any plot.


On Wed, Sep 28, 2011 at 9:14 AM, Stephen George
wrote:

>  On 28/09/2011 4:32 PM, Klonuo Umom wrote:
>
> Please consider:
>
> plot([1, 2, 3, 4], label='line 1')
> twinx()
> plot([11, 12, 11, 14], label='line 2')
> legend()
>
>
>  will draw only label for 'line 2'
>
>  plot([1, 2, 3, 4], label='line 1')
> legend()
> twinx()
> plot([11, 12, 11, 14], label='line 2')
> legend()
>
>
>  same result, as it will overwrite label 'line 1' with label 'line 2'
>
>  How to deal with this, without manually positioning legends and if
> possible including all annotated plot lines in one legend?
>
>
>  Thanks
>
>
> I would do something like
>
> from matplotlib import pylab
>
> LegendText = []
>
> pylab.twinx() # << had to move before first plot else it blew up
>
> pylab.plot([1, 2, 3, 4] )
> LegendText.append('line 1')
>
> pylab.plot([11, 12, 11, 14])
> LegendText.append('line 2')
>
> pylab.legend( LegendText , loc='lower right')
>
> pylab.show()
>
>
> Don't know if there is a better way
> Steve
>
>
> --
> 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] Using labels with "twinx()"

2011-09-28 Thread Klonuo Umom
Thanks JJ,

`axes_grid1` seems to handle this issue

On Wed, Sep 28, 2011 at 4:01 PM, Jae-Joon Lee  wrote:
>
> On Wed, Sep 28, 2011 at 3:32 PM, Klonuo Umom  wrote:
> > How to deal with this, without manually positioning legends and if possible
> > including all annotated plot lines in one legend?
>
> *twinx* creates a new axes. Thus there are TWO axes, and you need to
> do some manual adjustment. I believe that the solution suggested by
> Stephen George is essentially the best way, although you may try to
> tweak things using the Axes.get_legend_handles_labels method (
> http://matplotlib.sourceforge.net/users/legend_guide.html#what-to-be-displayed
> ).
>
> Alternatively, you can try the axes_grid1 toolkit which automatically
> merges legends for you. Check out the example below.
>
> http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html#example-1-twinx
>
> Regards,
>
> -JJ

--
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 
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  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  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.so

Re: [Matplotlib-users] Histograms

2011-09-28 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  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 
> 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  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  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 infrastruct