Re: [Matplotlib-users] What is the proper way to set y tick labels for a histogram ?

 Re: [Matplotlib-users] What is the proper way to set y tick labels for a histogram ? From: John Hunter - 2008-02-22 14:15:41 ```On Fri, Feb 22, 2008 at 7:52 AM, Auré Gourrier wrote: > 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 ```

 [Matplotlib-users] What is the proper way to set y tick labels for a histogram ? From: Auré Gourrier - 2008-02-22 13:52:20 Attachments: Message as HTML ```Hi all, I'm plotting the histogram of a data set: x = datalist bins= 100 hist(x,bins,normed=0) #returns a tupple (n,bins,patches) 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. Can anyone give me a hint, Cheers, Aure _____________________________________________________________________________ Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail http://mail.yahoo.fr```
 Re: [Matplotlib-users] What is the proper way to set y tick labels for a histogram ? From: Antonio Gonzalez - 2008-02-22 13:59:51 ```Hi Aure, You could try: ax.set_yticklabels(ax.get_yticks()/len(x)) /Antonio Auré Gourrier wrote: > Hi all, > > I'm plotting the histogram of a data set: > > x = datalist > bins= 100 > hist(x,bins,normed=0) #returns a tupple (n,bins,patches) > > 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. > > Can anyone give me a hint, > > Cheers, > > Aure > > ------------------------------------------------------------------------ > Ne gardez plus qu'une seule adresse mail ! Copiez vos mails > ; > vers Yahoo! Mail > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > > ------------------------------------------------------------------------ > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users ```
 Re: [Matplotlib-users] What is the proper way to set y tick labels for a histogram ? From: John Hunter - 2008-02-22 14:15:41 ```On Fri, Feb 22, 2008 at 7:52 AM, Auré Gourrier wrote: > 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 ```