Michael Rawlins, on 2011-01-05 14:42, wrote: > Thanks for the detailed tutorial. I'm getting errors when I > attempt to use plt.subplots(1,1) and the newcm assignment. > > Traceback (most recent call last): > File "colorbar_Mytest2.py", line 17, in <module> > f, ax = plt.subplots(1,1) > AttributeError: 'module' object has no attribute 'subplots'
Ah, you must be using an older version of matplotlib - subplots is a (recently added) convenience shortcut for: f = plt.figure() ax = plt.subplot(1,1,1) It comes in handy when you're making lots of subplots by letting you do it with one call, instead of doing that one by one (as I have rewritten below, so you could run without having to upgrade your matplotlib. > Also, what does In and Out do, as in Out[68]: 0.34999? That's just the prompts from IPython - I *highly* recommend using IPython in place of the default python shell for interactive usage. In[10] is what I typed, Out[10] is the result of my command at In[10]. > Here are just a few of the errors I'm getting when executing > colorbar command with newcm. > Here's a simplified version that works for me: ouch! this code doesn't do quite what you want > from pylab import * Try to avoid doing this - because you will get unintended consequences such as the one on the following line. > vals = norm(np.linspace(14,40,1000)) This was meant to go *after* you initialize the 'norm' variable with norm = mpl.colors.Normalize(...). That's the norm I meant to be using. But because of the "from pylab import *" line, the norm function from numpy was imported - which is what was being used on that line as written in your code. so the vals= line is equivalent to vals = numpy.norm(np.linspace(14,40,1000)) which meant vals got assigned the value 886.25397758173483, and not at all what we wanted. We wanted it to get an array of 1000 numbers: vals = mpl.colors.Normalize(vmin=0, vmax=40)(np.linspace(14,40,1000)) That's where your trouble with newcm were coming from. Here's the complete example again, I've renamed the 'norm' variable to 'rawlins_norm' for clarity. import matplotlib as mpl import matplotlib.pyplot as plt from matplotlib import cm import numpy as np # Make a figure and axes with dimensions as desired. fig = plt.figure(figsize=(8,3)) ax1 = plt.subplot(2,1,1) ax2 = plt.subplot(2,1,2) # Set the colormap and norm to correspond to the data for which # the colorbar will be used. rawlins_norm = mpl.colors.Normalize(vmin=0, vmax=40) # here set colorbar min/max # the right place for vals vals = rawlins_norm(np.linspace(14,40,1000)) newcm = cm.colors.ListedColormap(cm.hot_r(vals)) cb1 = mpl.colorbar.ColorbarBase(ax1, cmap=cm.hot_r, norm=rawlins_norm, orientation='horizontal') cb1.set_label('"percent"') cb2 = mpl.colorbar.ColorbarBase(ax2, cmap=newcm, orientation='horizontal') cb2.set_label("colormap interval 0.0-1.0") plt.subplots_adjust(hspace=.7, bottom=.2) #comment out the next line to see the original (0-40 colormap) ax1.set_xlim(rawlins_norm((14,40))) plt.show() best, -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7
signature.asc
Description: Digital signature
------------------------------------------------------------------------------ Learn how Oracle Real Application Clusters (RAC) One Node allows customers to consolidate database storage, standardize their database environment, and, should the need arise, upgrade to a full multi-node Oracle RAC database without downtime or disruption http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users