logarithmic axis on colorbar

Hi Jody,

Thanks for the pointer. It looks like that should work nicely. I am
curious though if there isn't a more general way to provide the data to be
used for a colorbar without creating a plot. I guess you always need to
provide an Axes object.

Jon

···

On Fri, Sep 4, 2015 at 5:09 PM, Jody Klymak <jklymak at uvic.ca> wrote:

"""Demonstration of using norm to map colormaps onto data in non-linear ways."""
import numpy as npimport matplotlib.pyplot as pltimport matplotlib.colors as colorsfrom matplotlib.mlab import bivariate_normal
'''Lognorm: Instead of pcolor log10(Z1) you can have colorbars that havethe exponential labels using a norm.'''N = 100X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)]
# A low hump with a spike coming out of the top right. Needs to have# z/colour axis on a log scale so we see both hump and spike. linear# scale only shows the spike.Z1 = bivariate_normal(X, Y, 0.1, 0.2, 1.0, 1.0) + \
    0.1 * bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
fig, ax = plt.subplots(2, 1)
pcm = ax[0].pcolor(X, Y, Z1,
                   norm=colors.LogNorm(vmin=Z1.min(), vmax=Z1.max()),
                   cmap='PuBu_r')fig.colorbar(pcm, ax=ax[0], extend='max')
pcm = ax[1].pcolor(X, Y, Z1, cmap='PuBu_r')fig.colorbar(pcm, ax=ax[1], extend='max')fig.show()

This is not part of the release docs, but is on master, so should be
available soon. But basically you want to use `norm=colors.LogNorm()`

Cheers, Jody

On 4 Sep 2015, at 13:38 PM, Slavin, Jonathan <jslavin at cfa.harvard.edu> > wrote:

Hi all,

I'm wanting to plot an image that is logarithmically scaled, and I'd like
to have the associated colorbar ticks be logarithmic. So, for example, say
img is the image
fig,ax = plt.subplots()
cax = ax.imshow(np.log10(img))
fig.colorbar(cax)

gives me a colorbar with the tick labels with values that are the
log10(img) values, whereas I want the colorbar to be labeled with a
logarithmic axis and the img values. How could I do that? Any help would
be appreciated.

Thanks,
Jon

--
________________________________________________________
Jonathan D. Slavin Harvard-Smithsonian CfA
jslavin at cfa.harvard.edu 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
________________________________________________________

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

--
Jody Klymak
Jody M. Klymak - UVic Ocean Physics

--
________________________________________________________
Jonathan D. Slavin Harvard-Smithsonian CfA
jslavin at cfa.harvard.edu 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20150909/a1064fd6/attachment.html&gt;

http://matplotlib.org/examples/api/colorbar_only.html

Is this what you mean?

Eric

···

On 2015/09/09 4:35 AM, Slavin, Jonathan wrote:

I am curious though if there isn't a more general way to provide the
data to be used for a colorbar without creating a plot.