From: John H. <jdh...@ac...> - 2006-03-30 16:28:01
|
>>>>> "Sarah" == Sarah Mount <mou...@gm...> 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> color='r') 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 hist bars 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 rectangles. johnh@jitter:~> ipython -pylab /home/titan/johnh/local/lib/python2.3/site-packages/matplotlib/__init__.py:892: 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 [1]: n,bins,patches = hist(randn(1000), 20) In [2]: setp(patches) alpha: float 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] hatch: unknown height: float label: any string linewidth or lw: float lod: [True | False] transform: a matplotlib.transform transformation instance visible: [True | False] width: float x: float y: float 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 [3]: setp(patches, edgecolor='g', facecolor='b', linewidth=2); Hope this helps, JDH |