Hi, Matt

I am still struggling with this issue of creating non-square plots. I can now create an FRB, and get plots from it, but I cannot seem to get anything except square plots. And because my matplotlib experience is "limited", to say the least, I'm not sure exactly what the square plot represents. 

So, here is one of the SlicePlots from before, 1 kpc wide by 2 kpc tall (even though I would like it to be even taller, and even though it cuts off the side of the plot window).

from yt.mods import *
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.colorbar as cb
from matplotlib.colors import LogNorm
import numpy as np

pf = load("Strat_Box_hdf5_plt_cnt_0064")
slc = SlicePlot(pf, 'x', 'Density',center='c',width=((1,"kpc"),(2.0,"kpc")))
slc.annotate_title('This is a Density plot')
slc.save('test_2kpc.png')
slc.show()

and here is the plot:
http://i.imgur.com/wW64TYV.png

So, with the ultimate goal of creating an even taller plot with an FRB, and using your suggestions, I tried using an FRB, which is now working mostly

sl = pf.h.slice(2, pf.domain_center[2],fields=["Density","Temperature"] )
frb = sl.to_frb( (1.0, 'kpc'), (2048,1024),height=(2.0, 'kpc'))
fig = plt.figure()
ax = fig.add_axes([0.1,0.1,0.85,0.85])

ax.imshow(frb["Density"],
    origin="lower",
    norm = LogNorm(),
    clim = (1.0e-25,1.0e-22),
    cmap = "spectral")

fig.savefig("test_dens.png")

However, even given my current ("limited") matplotlib skills and doing a stretch with clim the best I could, this doesn't look right to me -- it seems to be square, and missing the parts above and below the galactic plane:
http://i.imgur.com/OGQiHUh.png

Any suggestions? 

thanks in advance, and for all your work on yt...
kathy


On Wed, Nov 27, 2013 at 7:06 AM, Matthew Turk <matthewturk@gmail.com> wrote:
Hi Kathy,

Sorry you're having trouble!

On Tue, Nov 26, 2013 at 1:21 PM, Kathy Eastwood <kathy.eastwood@nau.edu> wrote:
> Dear (very helpful) yt folk:
>
> I have been struggling with trying to make a slice plot of some FLASH data
> that is an odd size; the volume is 1 kpc square in x and y, and 40 kpc tall
> in z.  The grid sizes vary widely, as expected. I have two questions: one, I
> would like to understand the odd behavior that I get with regular
> SlicePLots, and I would like some help using the FixedResolutionBuffer,
> which I *suspect* is the way I want to go, but I have not been able to make
> it work.  I am using the newest version of yt (upgraded this morning!) on
> Mac OS 10.7.5.
>
> The SlicePlot weirdnesses:
> from yt.mods import *
> %matplotlib inline
> import matplotlib.pyplot as plt
> import matplotlib.image as mpimg
> import matplotlib.colorbar as cb
> import numpy as np
> pf = load("Strat_Box_hdf5_plt_cnt_0064")
> #First try a 20 kpc tall box
> slc = SlicePlot(pf, 'x',
> 'Density',center='c',width=((1,"kpc"),(20.0,"kpc")))
> slc.annotate_title('This is a Density plot')
> slc.save('test_20kpc.png')
> slc.show()
> #Please see plot at http://i.imgur.com/N65CNfU.png

Whoa!  That's pretty squished.

>
> #Now try a 5 kpc tall plot
> slc = SlicePlot(pf, 'x', 'Density',center='c',width=((1,"kpc"),(5.0,"kpc")))
> slc.annotate_title('This is a Density plot')
> slc.save('test_5kpc.png')
> slc.show()
>
> #Please see plot at http://i.imgur.com/L1YORNK.png ; note that it seems to
> filling
> #a different part of the plotting "window"
>
> #Now try a 2 kpc tall plot
> slc = SlicePlot(pf, 'x', 'Density',center='c',width=((1,"kpc"),(2.0,"kpc")))
> slc.annotate_title('This is a Density plot')
> slc.save('test_2kpc.png')
> slc.show()
>
> #Please see plot at http://i.imgur.com/Bq1WaIP.png ; note that it seems to
> filling
> #even MORE of the plotting "window", but that the density labels were cut
> off a bit.
>

Okay, so I *think* I might have an idea what's going on here.  I've
replicated the problem here, but I don't have any ideas how to fix it.
 It's basically just that (automatically) coming up with the right
aspect ratio for the *figure* is tricky when the image is not the
right aspect ratio.  I think Devin Silvia, Nathan Goldbaum and Kacper
Kowalik have all worked hard on this but not had a lot of success.  It
also looks to me like the FRB may have a uniform aspect ratio
(800x800) which may be contributing to the problem.  So, on to FRBs
...

>
> OK, now the part that doesn't work.  After reading, I decided that an frb
> must be
> the way to go, so I tried
> frb = FixedResolutionBuffer(slc, (0.0, 1.0, 0.0, 1.0), (1024,1024))
> plt.imshow(frb['Density'])
> plt.savefig('test_figure.png')
>
> and I get the following error.  Note: I also tried slc.to_frb and that
> didn't work either.
>
> ---------------------------------------------------------------------------
> AttributeError                            Traceback (most recent call last)
> <ipython-input-17-e68719d58ae4> in <module>()
> ----> 1 frb = FixedResolutionBuffer(slc, (0.0, 1.0, 0.0, 1.0), (1024,1024))
>       2 plt.imshow(frb['Density'])
>       3 plt.savefig('test_figure.png')
>       4
>       5
>
> /Users/kde/yt-x86_64/src/yt-hg/yt/visualization/fixed_resolution.pyc in
> __init__(self, data_source, bounds, buff_size, antialias, periodic)
>      89         self.antialias = antialias
>      90         self.data = {}
> ---> 91         self.axis = data_source.axis
>      92         self.periodic = periodic
>      93
>
> AttributeError: 'SlicePlot' object has no attribute 'axis'
>

Ah, this one we can fix.  Here what the FRB wants is actually the
slice itself, not the slice plot.  There are two ways to do this.  The
first is to grab the *existing* slice object:

sl = slc.data_source

and feed sl into a FixedResolutionBuffer creation.  But I think, since
you're going to avoid all of the slice plot machinery altogether, it'd
probably make more sense to take control of it with the data object
machinery directly.  So you can create a slice, which is a data
source, like this:

sl = pf.h.slice(2, pf.domain_center[2])

What I'm doing here is saying axis 2 (z) and at the z-th coordinate of
the domain center.  Now if we query sl, we get all of the data points;
this isn't what we want, since they are all different resolutions, so
we use the FRB.  sl objects have a handy way of making FRBs:

sl.to_frb( ...

this takes a width (which can be a tuple), a resolution, and
optionally a height.  help(sl.to_frb) will show the arguments and an
example.  Now the FRB can be queried like you would a data object, and
it gives back (N,N) arrays.  Hope that helps, and let us know!

-Matt

PS Those are some gorgeous simulation results, by the way.

> THanks in advance for any help.
> cheers
> kathy
>
>
> --
> 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@nau.edu
> deliveries: 602 S. Humphreys St., Bldg 19 Rm 209
>
> _______________________________________________
> yt-users mailing list
> yt-users@lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>



--
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@nau.edu
deliveries: 602 S. Humphreys St., Bldg 19 Rm 209