John,

Attached is a script illustrating how to make contourf plots with a log colorscale. I made some improvements in svn, as noted in the script, but you can still do it with the regular mpl release. All of this should carry through to basemap with no changes in basemap.

Eric

John wrote:
Well, it seems like I'm making progress, but it's stll not the plot I'm hoping to produce. Something seems strange. First, it does create a contourf plot, but I really need to take log(zdata) and use imshow (which seems to handly the INF issue, wheras contourf crashes). On another issue though, once the image is created, when I draw the map components it covers the image entirely.. so I just see coastlines, meridians, etc on a whilte background as if I had never plotted the data. Thanks for helping with this! I'm really trying to make a movement with my colleagues away from matlab, but I need to have things operating more smoothly... lately it hasn't been going so well. This is a great product you've made!


------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/


------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

'''
Demonstrate use of a log color scale in contourf
'''

import pylab as P # or "from matplotlib import pyplot as P" if you are using svn
import numpy
from numpy import ma
from matplotlib import colors
from matplotlib import ticker

z = numpy.arange(10000, dtype=float)
z.shape = 100,100

z = numpy.power(10, 5*z/z.max())

# Put in some negative values to cause trouble with logs:
z[:5, :5] = -1

# The svn version will do the following automatically, and
# print a warning; but with the released mpl you must do it
# yourself.
z = ma.masked_where(z<= 0, z)


lev_exp = numpy.arange(0, numpy.log10(z.max())+1)
print z.max(), z.min()
print lev_exp
levs = numpy.power(10, lev_exp)

# With svn, automatic selection of levels works; setting the
# locator tells contourf to use a log scale:
#cs = P.contourf(z, locator=ticker.LogLocator())

# but with the current mpl release, you must carefully
# set the levels yourself, and set the norm like this:
cs = P.contourf(z, levs, norm=colors.LogNorm())

# Of course the form above still works in svn also.

#The 'extend' kwarg, however, does not work yet with a log
#scale either in the release or in svn.

cbar = P.colorbar()

P.show()


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to