From: Ryan M. <rm...@gm...> - 2009-05-20 15:22:15
|
On Wed, May 20, 2009 at 10:04 AM, John Hunter <jd...@gm...> wrote: > On Wed, May 20, 2009 at 9:53 AM, Ryan May <rm...@gm...> wrote: > > > Thanks for the full example, but if you carefully read the exception, it > was > > telling you the problem. :) plot1 here is an axes object, which does not > > have a colorbar() method. Instead, you should change that to: > > > > plt.colorbar() > > > > Assuming everything else was working, you should be good to go with this > > change. > > > > It looks like Markus is trying to use the API, so rather than suggest > the pyplot colorbar method, I suggest using the figure instance > method. Markus the pyplot method plt.colorbar is a thin wrapper > around the figure method fig.colorbar -- see also: > > > http://matplotlib.sourceforge.net/faq/usage_faq.html#matplotlib-pylab-and-pyplot-how-are-they-related > > > http://matplotlib.sourceforge.net/api/figure_api.html#matplotlib.figure.Figure.colorbar > > It may be a good idea and refer to the return value of fig.add_subplot > as "ax" or something that, rather than "plot1" because add_subplot > returns an Axes instance and thus ax is a better mnemonic; see > > > http://matplotlib.sourceforge.net/api/figure_api.html#matplotlib.figure.Figure.add_subplot > > So I suggest something like:: > > fig = plt.figure() > > ax1 = fig.add_subplot(231,aspect='equal') > ax1.pcolor(xsr) > ax1.axis([0, 127, 0, 127]) > fig.colorbar() Except that it won't work like that. :) (I actually tried that the first time) You need to give Figure.colorbar() the mappable as the first argument. So this would then become: ax1 = fig.add_subplot(231,aspect='equal') pc = ax1.pcolor(xsr) ax1.axis([0, 127, 0, 127]) fig.colorbar(pc) Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma Sent from Norman, Oklahoma, United States |