Getting started with bar charts

"Derek Hohls" <DHohls@...1229...> writes:

It appears the manual (which I assume might be able to help me) is not
"downloadable". The link :
http://matplotlib.sourceforge.net/users_guide_0.87.1.pdf

For some reason, downloading this file fails quite often. Perhaps it
should be distributed using the same sf.net download mechanism as the
software itself?

Try using some software that knows how to resume interrupted
downloads. E.g., run

curl -O -C - http://matplotlib.sourceforge.net/users_guide_0.87.1.pdf

as many times as needed to get the whole file.

http://www.scipy.org/Cookbook/Matplotlib/BarCharts
shows how to setup labels for a bar chart - but it would be great if
there was a line-by-line explanation of what each step means

I think the best way to understand the examples is to start up
"ipython -pylab", copy/paste the examples line by line, inspect the
resulting objects, get help on the mysterious functions (e.g. type
?gca in ipython to find out what gca does), form hypotheses on what
the various steps do, and test the hypotheses with experiments.

setting line widths, font sizes, bar colours etc

bar returns a list of Rectangle objects:

    In [19]: bar([1,2,3], [4,5,6])
    Out[19]:
    [<matplotlib.patches.Rectangle instance at 0x2aaab2f33290>,
     <matplotlib.patches.Rectangle instance at 0x2aaab2f33200>,
     <matplotlib.patches.Rectangle instance at 0x2aaab2f33248>]

Capture these objects and use getp and setp on them:

    In [20]: recs = _

    In [21]: getp(recs[0])

  ...

    In [22]: setp(recs[0], 'facecolor')
        facecolor: any matplotlib color - see help(colors)

    In [23]: help(colors)

  ...

    In [24]: setp(recs[0], 'facecolor', 'red')
    Out[24]: [None]

For font sizes you need to get a handle to the relevant Text objects.
For axis texts, look at the object returned by gca():

    In [36]: setp(getp(gca(), 'yticklabels'), 'fontsize', 18)

Most of these settings are easier to do by using keyword arguments of
the initial commands:

    In [38]: bar([1,2,3], [4,5,6], color=['red', 'green', 'blue'])

But the getp/setp method is great for tuning the image interactively
and learning about what can be customized.

···

--
Jouni