## Re: [Matplotlib-users] logaritmic histogram

 Re: [Matplotlib-users] logaritmic histogram From: John Hunter - 2005-12-21 12:38:42 ```>>>>> "Jiri" == Jiri Polcar writes: Jiri> On Tue, Dec 20, 2005 at 07:16:33PM -0600, John Hunter wrote: >> Just set the xscale attribute for the axes to be 'log' (and >> make sure you have strictly positive data, of course) >> >> ax = subplot(111, xscale='log') ax.hist(X, 100) >> Jiri> It works. Thanke you very mych. But if I want to set Jiri> logaritmic Y-axes also: Jiri> ax = subplot(111, xscale='log', yscale='log' ) Jiri> I get: My guess is that this is caused by having a histogram bin with no values, and the log of 0 is undefined. It would be nice if we could fix this code to be fault tolerant to invalid data, as we did for line data. You can inspect the hist output by doing n, bins = matplotlib.mlab.hist(X, 100) and then seeing what the minimum n is. If it is 0, that is likely to be the source of your troubles, Jiri> PS: 'X' contais whole nubers >= 1. You might try setting the bins manually to workaround this problem, eg define the bins such that there are no empty bins. mybins = nx.arange(1,20) n, bins = matplotlib.mlab.hist(X, bins) Note that matplotlib.mlab.hist is the non-plotting version of hist that actually computes the histogram. JDH ```

 [Matplotlib-users] logaritmic histogram From: Jiri Polcar - 2005-12-14 12:02:39 ``` Hallo, I have (another) simple question. How can I make logaritmic histogram? If I use ( X is an array of input data ): from pylab import * logX = log10( X ) n, bins, patches = hist( logX, 50 ) show() I must take a special care for x-axis labels. Is possible to use semilogx()? How? -- JP ```
 Re: [Matplotlib-users] logaritmic histogram From: John Hunter - 2005-12-21 01:24:11 ```>>>>> "Jiri" == Jiri Polcar writes: Jiri> Hallo, I have (another) simple question. How can I make Jiri> logaritmic histogram? If I use ( X is an array of input Jiri> data ): Jiri> from pylab import * logX = log10( X ) n, bins, patches = Jiri> hist( logX, 50 ) show() Jiri> I must take a special care for x-axis labels. Is possible to Jiri> use semilogx()? How? Just set the xscale attribute for the axes to be 'log' (and make sure you have strictly positive data, of course) ax = subplot(111, xscale='log') ax.hist(X, 100) JDH ```
 Re: [Matplotlib-users] logaritmic histogram From: Jiri Polcar - 2005-12-21 09:16:23 ```On Tue, Dec 20, 2005 at 07:16:33PM -0600, John Hunter wrote: > > Just set the xscale attribute for the axes to be 'log' (and make sure > you have strictly positive data, of course) > > ax = subplot(111, xscale='log') > ax.hist(X, 100) > It works. Thanke you very mych. But if I want to set logaritmic Y-axes also: ax = subplot(111, xscale='log', yscale='log' ) I get: Traceback (most recent call last): File "bin/plot_msg_len_dist.py", line 22, in ? savefig( 'smith_msg_length_dist.png' ) File "/usr/lib/python2.4/site-packages/matplotlib/pylab.py", line 791, in savefig return fig.savefig(*args, **kwargs) File "/usr/lib/python2.4/site-packages/matplotlib/figure.py", line 645, in savefig self.canvas.print_figure(*args, **kwargs) File "/usr/lib/python2.4/site-packages/matplotlib/backends/backend_gtkagg.py", line 93, in print_figure try: agg.print_figure(filename, dpi, facecolor, edgecolor, orientation) File "/usr/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py", line 445, in print_figure self.draw() File "/usr/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py", line 382, in draw self.figure.draw(renderer) File "/usr/lib/python2.4/site-packages/matplotlib/figure.py", line 520, in draw for a in self.axes: a.draw(renderer) File "/usr/lib/python2.4/site-packages/matplotlib/axes.py", line 1402, in draw a.draw(renderer) File "/usr/lib/python2.4/site-packages/matplotlib/patches.py", line 127, in draw tverts = self._transform.seq_xy_tups(verts) ValueError: Domain error on nonlinear Transformation::seq_xy_tups operator()(thisx, thisy) make: *** [smith_msg_length_dist.png] Error 1 PS: 'X' contais whole nubers >= 1. -- JP ```
 Re: [Matplotlib-users] logaritmic histogram From: John Hunter - 2005-12-21 12:38:42 ```>>>>> "Jiri" == Jiri Polcar writes: Jiri> On Tue, Dec 20, 2005 at 07:16:33PM -0600, John Hunter wrote: >> Just set the xscale attribute for the axes to be 'log' (and >> make sure you have strictly positive data, of course) >> >> ax = subplot(111, xscale='log') ax.hist(X, 100) >> Jiri> It works. Thanke you very mych. But if I want to set Jiri> logaritmic Y-axes also: Jiri> ax = subplot(111, xscale='log', yscale='log' ) Jiri> I get: My guess is that this is caused by having a histogram bin with no values, and the log of 0 is undefined. It would be nice if we could fix this code to be fault tolerant to invalid data, as we did for line data. You can inspect the hist output by doing n, bins = matplotlib.mlab.hist(X, 100) and then seeing what the minimum n is. If it is 0, that is likely to be the source of your troubles, Jiri> PS: 'X' contais whole nubers >= 1. You might try setting the bins manually to workaround this problem, eg define the bins such that there are no empty bins. mybins = nx.arange(1,20) n, bins = matplotlib.mlab.hist(X, bins) Note that matplotlib.mlab.hist is the non-plotting version of hist that actually computes the histogram. JDH ```