[yt-users] yet another plot problem!
Britton Smith
brittonsmith at gmail.com
Mon Feb 3 13:09:06 PST 2014
Hi Kathy,
It looks like the problem is that "plots" is a list, but the call to
colorbar is expecting an actual plot object. I think you can fix this by
changing plots to plots[0], as in:
cbar = fig.colorbar(plots[0],cax=cax, orientation=orient)
Britton
On Mon, Feb 3, 2014 at 4:01 PM, Kathy Eastwood <kathy.eastwood at nau.edu>wrote:
> Dear yt folks....
>
> This is probably a straightup matplotlib question and not a yt question,
> but....it was working until I got to the colorbar, and I am now confused.
> Thanks for any help...
> kathy
>
> here is the code:
>
> from yt.imods import *
> import matplotlib as mpl
> import matplotlib.pyplot as plt
> #import matplotlib.colorbar as cb
> from matplotlib.colors import LogNorm
> #import numpy as np
>
> ts = TimeSeriesData.from_filenames("Strat_Box_hdf5_plt_cnt_01*")
>
> padding = 0.05
> nx = 5 #number of time series images, plus will need space for vertical
> colorbar
> ny = 1 #might want to change this later!
> #Assuming that all images are the same shape and size
>
> width = nx +1 #I think this is inches, not sure
> height = 4
> fig = plt.figure(figsize=(width,height),frameon=False)
>
> #Trying to save 0.91 to 0.95 horizontally for the colorbar
> sizex = 0.85/nx
> sizey = 0.90/ny
>
> haxes = []
>
> for j in range(ny):
> haxes.append([])
> for i in range(nx):
> left = padding + i*sizex
> bottom = padding + j*sizey
> ax = fig.add_axes([left, bottom, sizex, sizey],frameon=False)
> ax.xaxis.set_visible(False)
> ax.yaxis.set_visible(False)
> haxes[-1].append(ax)
>
> cax = fig.add_axes([0.9, 0.05, 0.04, sizey],frameon=False)
> cax.xaxis.set_visible(False)
> cax.yaxis.set_visible(False)
>
> for i, pf in enumerate(ts):
> sl = pf.h.slice(0,
> pf.domain_center[0],fields=["Density","Temperature"] )
> frb = sl.to_frb( (1.0, 'kpc'), (4096,1024),height=(4.0, 'kpc'))
> dens_axes = [haxes[0][i]]
> plots = [dens_axes[0].imshow(frb["Density"], origin='lower',
> norm=LogNorm())]
>
> title=[r'$\mathrm{Density}\ (\mathrm{g\ cm^{-3}})$']
> orient = 'vertical'
>
> cbar = fig.colorbar(plots,cax=cax, orientation=orient)
> cbar.set_label(title)
> fig.savefig('ts_test')
>
> Here are the errors:
>
> --------------------------------------------------------------------------AttributeError Traceback (most recent call last)<ipython-input-7-e0dcab3d98fe> in <module>() 2 orient = 'vertical' 3 ----> 4 cbar = fig.colorbar(plots,cax=cax, orientation=orient) 5 cbar.set_label(title) 6
> /Users/kde/yt-x86_64/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-macosx-10.4-x86_64.egg/matplotlib/figure.pyc in colorbar(self, mappable, cax, ax, use_gridspec, **kw) 1449 cax, kw = cbar.make_axes(ax, **kw) 1450 cax.hold(True)-> 1451 cb = cbar.colorbar_factory(cax, mappable, **kw) 1452 1453 self.sca(current_ax)
> /Users/kde/yt-x86_64/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-macosx-10.4-x86_64.egg/matplotlib/colorbar.pyc in colorbar_factory(cax, mappable, **kwargs) 1272 cb = ColorbarPatch(cax, mappable, **kwargs) 1273 else:-> 1274 cb = Colorbar(cax, mappable, **kwargs) 1275 1276 mappable.callbacksSM.connect('changed', cb.on_mappable_changed)
> /Users/kde/yt-x86_64/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-macosx-10.4-x86_64.egg/matplotlib/colorbar.pyc in __init__(self, ax, mappable, **kw) 850 # Ensure the given mappable's norm has appropriate vmin and vmax set 851 # even if mappable.draw has not yet been called.--> 852 mappable.autoscale_None() 853 854 self.mappable = mappable
> AttributeError: 'list' object has no attribute 'autoscale_None'
>
>
>
> --
> Kathy DeGioia Eastwood, Ph.D.
> Professor of Physics and Astronomy
> Northern Arizona University
> Flagstaff, AZ 86011-6010
> Ph: 928-523-7159 FX: 928-523-1371
> Kathy.Eastwood at nau.edu
> deliveries: 602 S. Humphreys St., Bldg 19 Rm 2
>
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20140203/dd34f29a/attachment.html>
More information about the yt-users
mailing list