From: Sarah Mount <mount.sarah@gm...> - 2006-03-30 15:57:18
maybe this is a daft question, but is there a simple way of drawing
several histograms on top of one another on the same axes?
Right now I can't even figure out how to change the bar colour in a
script. I've looked through the code in axes.py and this looks like it
*ought* to be right, but isn't:
ax1 =3D pylab.axes(...)
n, bins, patches =3D ax1.hist(data, color=3D'r')
Any ideas would be very much appreciated ...
From: John Hunter <jdhunter@ac...> - 2006-03-30 16:28:01
>>>>> "Sarah" == Sarah Mount <mount.sarah@...> writes:
Sarah> Hi all, maybe this is a daft question, but is there a
Sarah> simple way of drawing several histograms on top of one
Sarah> another on the same axes?
Sarah> Right now I can't even figure out how to change the bar
Sarah> colour in a script. I've looked through the code in axes.py
Sarah> and this looks like it *ought* to be right, but isn't:
Sarah> ax1 = pylab.axes(...) n, bins, patches = ax1.hist(data,
Sarah> Any ideas would be very much appreciated ...
Ahh yes, the docs could be a little clearer. They say
kwargs are used to update the properties of the
To make sense of this you would need to know that the bars are
matplotlib.patch.Rectangle objects, and know what properties could be
set on them. We have a goal of making the documentation thorough with
respect to kwargs. In the meantime, scroll through the rectangle
class documentation at
http://matplotlib.sf.net/matplotlib.patches.html for insight.
Here is a hint about how to find these kinds of things out yourself:
Fire up an interactive python shell with support for matplotlib (see
http://matplotlib.sf.net/interactive.html). I use ipython
(http://ipython.scipy.org) in pylab mode. Make a histogram and use
the setp functionality to inspect the properties of the patches
returned by hist. patches are 2D objects like polygons, circles and
johnh@...:~> ipython -pylab
Python 2.3.4 (#12, Jul 2 2004, 09:48:10)
Type "copyright", "credits" or "license" for more information.
IPython 0.7.2.svn -- An enhanced Interactive Python.
? -> Introduction to IPython's features.
%magic -> Information about IPython's 'magic' % functions.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
Welcome to pylab, a matplotlib-based Python environment.
For more information, type 'help(pylab)'.
In : n,bins,patches = hist(randn(1000), 20)
In : setp(patches)
animated: [True | False]
antialiased or aa: [True | False]
bounds: (left, bottom, width, height)
clip_box: a matplotlib.transform.Bbox instance
clip_on: [True | False]
edgecolor or ec: any matplotlib color - see help(colors)
facecolor or fc: any matplotlib color - see help(colors)
figure: a matplotlib.figure.Figure instance
fill: [True | False]
label: any string
linewidth or lw: float
lod: [True | False]
transform: a matplotlib.transform transformation instance
visible: [True | False]
zorder: any number
Scrolling through this list, you see things like edgecolor and
facecolor. You can pass these as kwargs to hist, or use setp
In : setp(patches, edgecolor='g', facecolor='b', linewidth=2);
Hope this helps,