logarithmic colormaps for imshow

In mpl_toolkits.basemap there is a module cm.

I have been using the cm.s3pcpn colormap for some plots which require
logarithmic coloring. The cm.s3pcpn_l colormap is also available (apparently
a linear version).

I wanted to know whether there were any other logarithmic colormaps
available... for example, I would like to use gist_rainbow or gist_ncar, but
I haven't been able to so far using the example below. Suggestions?

The relevant section of code is here:

dmn = 0.00001
dmx = 1000000
logspace = 10.**np.linspace(dmn, dmx, 100)
clevs = logspace
im = m.imshow(topodat,cmap=cm.s3pcpn,vmin=clevs[0],vmax=clevs[-1])

···

--
View this message in context: http://www.nabble.com/logarithmic-colormaps-for-imshow-tp25392480p25392480.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

John [H2O] wrote:

In mpl_toolkits.basemap there is a module cm.

I have been using the cm.s3pcpn colormap for some plots which require
logarithmic coloring. The cm.s3pcpn_l colormap is also available (apparently
a linear version).

I wanted to know whether there were any other logarithmic colormaps
available... for example, I would like to use gist_rainbow or gist_ncar, but
I haven't been able to so far using the example below. Suggestions?

In addition to specifying the cmap, specify the norm as a LogNorm instance:

from matplotlib.colors import LogNorm

im = imshow(.... cmap=... , norm=LogNorm(vmin=clevs[0], vmax=clevs[-1]))

Try something like that.

Eric

···

The relevant section of code is here:

dmn = 0.00001
dmx = 1000000
logspace = 10.**np.linspace(dmn, dmx, 100) clevs = logspace
im = m.imshow(topodat,cmap=cm.s3pcpn,vmin=clevs[0],vmax=clevs[-1])

Must be something about asking the right question...

This works perfectly.

For those interested, my code is now as:
    dmn = 0.00001
    dmx = 1000000
    logspace = 10.**np.linspace(dmn, dmx, 100)
    clevs = logspace
    colmap = pyplot.get_cmap('gist_ncar')
    im =
m.imshow(topodat,cmap=colmap,norm=LogNorm(vmin=clevs[0],vmax=clevs[-1]))

    ## CREATE COLORBAR
    ## make a copy of the image object
    ## use non normalized colormap
    im2 = copy.copy(im)
    im2.set_cmap(colmap)
    ## create new axis for colorbar.
    cax = pyplot.axes([l+w+0.025, b, 0.025, h]) # setup colorbar axes
    ## using im2, not im (hack to prevent colors from being
    ## too compressed at the low end on the colorbar - results
    ## from highly nonuniform colormap)
    pyplot.colorbar(im2, cax, format='%3.2g') # draw colorbar
    ## reset colorbar tick labels
    clabels = clevs[::10]
    clabels.append(clevs[-1])
    cax.set_yticks(np.linspace(0,1,len(clabels)))
    cax.set_yticklabels(['%3.2g' % cl for cl in clabels])
    ## make the original axes current again
    pyplot.axes(ax)

···

--
View this message in context: http://www.nabble.com/logarithmic-colormaps-for-imshow-tp25392480p25397260.html
Sent from the matplotlib - users mailing list archive at Nabble.com.