pcolor loglog

I have the need to make a pcolor loglog plot. Unfortunately I

    > can't figure out how - as near as I can tell it's impossible,
    > pcolor loglog just plain isn't supported. It seems like the

The log transformation is a property of the x and y axes, not of the
plot type.

    > ability to logify arbitrary axes would be a good idea
    > (there's got to be *somebody* out there who wants a semilog
    > polar projection) but I can't find it anywhere. Suggestions?
    > Right now my best idea is to do the log transformation myself
    > (eww) and then modify the axis legend (eww).

    > The following code was a vague attempt to force pcolor to use
    > loglog scale, but it crashes with the message "Aborted" -
    > seems like a suboptimal error message. I should point out

When posting code to expose a bug, it is most helpful to post a script
that actually does something -- eg the "main" function in your script
is never called -- as well as the contextual information like which
backend you are running, platform information and so on. Most of this
contextual information is provided by running a script with
--verbose-helpful and reporting the output.

    > that I'm currently using 0.72.1 since updating the corporate
    > version would take a little work, but I haven't seen anything
    > in the 0.73.1 docs that imply that's changed. So if it has,
    > lemme know and I'll go get someone to update. :slight_smile:

Getting log transformations in the presence of non-positive data now
works better than it used to -- most of the fixes in this area were in
0.72 so your version should be OK. For technical reasons, some plot
types work better than others (eg plot is more robust than pcolor) in
handling illegal data. But all that aside, there is no reason you
can't do loglog pcolor plots, provided you make the right calls and
take care to pass in legal data. The example script below illustrates
how, with comments. It's tested on matplotlib-cvs on linux using
GTKAgg, but I am pretty confident that it will run on 0.72.x on
windows with other backends as well. Let me know.

JDH

import matplotlib
from matplotlib import pylab

# WRONG: import Numeric as Numeric
# Importing Numeric or numarray manually with pylab is not
# recommended. pylab includes it's own Numeric/numarray switcher in
# matplotlib.numerix as controlled by the numerix rc setting. If you
# import your own, you can get into trouble with array
# incompatibility. Something like the following is recommended
import matplotlib.numerix as nx

def main(argv):

    # WRONG: pylab.loglog([1,100],[1,100])
    # You don't really want to plot the log of this line do you? What
    # you want to do is set the xscale and yscale to be 'log'; see below

    ax = pylab.subplot(111)
    x = y = nx.arange(1.,100.)
    X,Y = matplotlib.mlab.meshgrid(x,y)

    # Now pass in X and Y explicitly to pcolor. The default X and Y if you
    # don't pass them in will be index arrays starting at 0, which can
    # lead to a log problem since they contain non-positive data
    pylab.pcolor( X, Y, X*Y, shading = "flat" )

    # make sure the axis limits are positive before setting the log
    # scale since the transformations also apply to the axis tick locations
    pylab.axis([1., 100., 1., 100.])

    # Now set the xaxis and yaxis to a log scale
    pylab.set(ax, xscale='log', yscale='log')
    #pylab.savefig("/home/zorba/stats/color.png")

main()
pylab.show()