Re : Matplotlib-users Digest, Vol 21, Issue 36

Date: Fri, 22 Feb 2008 08:15:34 -0600
From: “John Hunter” <jdh2358@…287…>
Subject: Re: [Matplotlib-users] What is the proper way to set y tick
labels for a histogram ?
To: " Aur? Gourrier " <aurelien.gourrier@…136…>
Cc: matplotlib-users@…1738…net
Message-ID:
<88e473830802220615u71fb3bedj235179eca2ac6483@…288…>
Content-Type: text/plain; charset=ISO-8859-1

Rather trivial… but instead of the plotting the counts n, I’d like to plot
the realtive percentage counts, i.e. n/len(x). I can’t really use the option
normed = 1 which plots n/(len(x)*dbins). I guess the simplest way would be
to simply change the yticklabels (by dividing them by len(x)). The thing is
that I simply cannot find out how to do this…

I tried using the axes.set_yticklabels() but doesn’t work. I’ve also tried
to find the child containing the label but couldn’t find it (not in Axes,
nor in YAxis etc…). I guess it must be a Text instance.

You can set your own custom tick formatter:

import matplotlib.ticker as ticker

N = len(x)
def fmt_percent(x, pos=None):

return ‘%1.2f’%(float(x)/N)

ax.xaxis.set_major_formatter(ticker.FuncFormatter(fmt_percent)). See
>http://matplotlib.sourceforge.net/examples/custom_ticker1.py
for a
complete example.

JDH

Thanks, that’s something I had not looked into yet and will definetly be useful for other pbs I had…
Cheers,
Aure

···

On Fri, Feb 22, 2008 at 7:52 AM, Aur? Gourrier ><aurelien.gourrier@…136…> wrote:


Yahoo! Mail : un mail innovant avec Messenger compatible Windows Live + stockage illimité.