From: Eric F. <ef...@ha...> - 2010-02-17 19:00:27
|
Jan Strube wrote: > Dear matplotters, > encouraged from the excellent response times to my last problem, I am > trying to explore more features of matplotlib. > > My current problem is with hexbin. > I have been using numpy.histogram2d and imshow so far for 2d histograms, > but I must admit that hexbin looks quite pretty. > > In order to emphasize small differences over a large scale, I am using > hexbin with the bins='log' option. > The result is very nice, but when I add a pyplot.colorbar(), I would > like to have the original number of entries on the ticks, not their log10. > > Ideally, I'd change the yaxis of the colorbar to a logscale, and use > numpy.power(10, yaxis_values) on it. > I think colorbar().ax.set_yscale('log') should do what I need for the > first part, but how do I get the original number of entries back, rather > than their log10. > I could cheat and simply replace each ticklabel with 10^ticklabel, but I > don't even know how to do that. Offhand, I suspect this would be the best solution at present, if the only problem now is that you want the ticklabels written differently. Try using the "format" kwarg of the colorbar, supplying either a format string or a formatter. Something like this (untested): from matplotlib.ticker import LogFormatter class LogFormatterHB(LogFormatter): def __call__(self, v, pos=None): vv = self._base ** v return LogFormatter.__call__(self, vv, pos) ... cbar = colorbar( ... , format=LogFormatterHB()) Eric |