<div dir="ltr"><div><div><div><div><div><div>Hi, Matt<br><br>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.  <br>
<br></div>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).<br><br>from yt.mods import *<br>%matplotlib inline<br>
import matplotlib.pyplot as plt<br>import matplotlib.colorbar as cb<br>from matplotlib.colors import LogNorm<br>import numpy as np<br><br>pf = load("Strat_Box_hdf5_plt_cnt_0064")<br>slc = SlicePlot(pf, 'x', 'Density',center='c',width=((1,"kpc"),(2.0,"kpc")))<br>
slc.annotate_title('This is a Density plot')<br>slc.save('test_2kpc.png')<br>slc.show()<br><br></div>and here is the plot:<br><a href="http://i.imgur.com/wW64TYV.png">http://i.imgur.com/wW64TYV.png</a><br>
<br></div>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<br><br>sl = pf.h.slice(2, pf.domain_center[2],fields=["Density","Temperature"] )<br>
frb = sl.to_frb( (1.0, 'kpc'), (2048,1024),height=(2.0, 'kpc')) <br>fig = plt.figure()<br>ax = fig.add_axes([0.1,0.1,0.85,0.85])<br><br>ax.imshow(frb["Density"],<br>    origin="lower",<br>
    norm = LogNorm(), <br>    clim = (1.0e-25,1.0e-22),<br>    cmap = "spectral")<br><br>fig.savefig("test_dens.png")<br><br></div>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:<br>
<a href="http://i.imgur.com/OGQiHUh.png">http://i.imgur.com/OGQiHUh.png</a><br><br></div>Any suggestions?  <br><br></div>thanks in advance, and for all your work on yt...<br>kathy<br></div><div class="gmail_extra"><br><br>
<div class="gmail_quote">On Wed, Nov 27, 2013 at 7:06 AM, Matthew Turk <span dir="ltr"><<a href="mailto:matthewturk@gmail.com" target="_blank">matthewturk@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Kathy,<br>
<br>
Sorry you're having trouble!<br>
<div><div class="h5"><br>
On Tue, Nov 26, 2013 at 1:21 PM, Kathy Eastwood <<a href="mailto:kathy.eastwood@nau.edu">kathy.eastwood@nau.edu</a>> wrote:<br>
> Dear (very helpful) yt folk:<br>
><br>
> I have been struggling with trying to make a slice plot of some FLASH data<br>
> that is an odd size; the volume is 1 kpc square in x and y, and 40 kpc tall<br>
> in z.  The grid sizes vary widely, as expected. I have two questions: one, I<br>
> would like to understand the odd behavior that I get with regular<br>
> SlicePLots, and I would like some help using the FixedResolutionBuffer,<br>
> which I *suspect* is the way I want to go, but I have not been able to make<br>
> it work.  I am using the newest version of yt (upgraded this morning!) on<br>
> Mac OS 10.7.5.<br>
><br>
> The SlicePlot weirdnesses:<br>
> from yt.mods import *<br>
> %matplotlib inline<br>
> import matplotlib.pyplot as plt<br>
> import matplotlib.image as mpimg<br>
> import matplotlib.colorbar as cb<br>
> import numpy as np<br>
> pf = load("Strat_Box_hdf5_plt_cnt_0064")<br>
> #First try a 20 kpc tall box<br>
> slc = SlicePlot(pf, 'x',<br>
> 'Density',center='c',width=((1,"kpc"),(20.0,"kpc")))<br>
> slc.annotate_title('This is a Density plot')<br>
> slc.save('test_20kpc.png')<br>
> slc.show()<br>
> #Please see plot at <a href="http://i.imgur.com/N65CNfU.png" target="_blank">http://i.imgur.com/N65CNfU.png</a><br>
<br>
</div></div>Whoa!  That's pretty squished.<br>
<div class="im"><br>
><br>
> #Now try a 5 kpc tall plot<br>
> slc = SlicePlot(pf, 'x', 'Density',center='c',width=((1,"kpc"),(5.0,"kpc")))<br>
> slc.annotate_title('This is a Density plot')<br>
> slc.save('test_5kpc.png')<br>
> slc.show()<br>
><br>
> #Please see plot at <a href="http://i.imgur.com/L1YORNK.png" target="_blank">http://i.imgur.com/L1YORNK.png</a> ; note that it seems to<br>
> filling<br>
> #a different part of the plotting "window"<br>
><br>
> #Now try a 2 kpc tall plot<br>
> slc = SlicePlot(pf, 'x', 'Density',center='c',width=((1,"kpc"),(2.0,"kpc")))<br>
> slc.annotate_title('This is a Density plot')<br>
> slc.save('test_2kpc.png')<br>
> slc.show()<br>
><br>
> #Please see plot at <a href="http://i.imgur.com/Bq1WaIP.png" target="_blank">http://i.imgur.com/Bq1WaIP.png</a> ; note that it seems to<br>
> filling<br>
> #even MORE of the plotting "window", but that the density labels were cut<br>
> off a bit.<br>
><br>
<br>
</div>Okay, so I *think* I might have an idea what's going on here.  I've<br>
replicated the problem here, but I don't have any ideas how to fix it.<br>
 It's basically just that (automatically) coming up with the right<br>
aspect ratio for the *figure* is tricky when the image is not the<br>
right aspect ratio.  I think Devin Silvia, Nathan Goldbaum and Kacper<br>
Kowalik have all worked hard on this but not had a lot of success.  It<br>
also looks to me like the FRB may have a uniform aspect ratio<br>
(800x800) which may be contributing to the problem.  So, on to FRBs<br>
...<br>
<div class="im"><br>
><br>
> OK, now the part that doesn't work.  After reading, I decided that an frb<br>
> must be<br>
> the way to go, so I tried<br>
> frb = FixedResolutionBuffer(slc, (0.0, 1.0, 0.0, 1.0), (1024,1024))<br>
> plt.imshow(frb['Density'])<br>
> plt.savefig('test_figure.png')<br>
><br>
> and I get the following error.  Note: I also tried slc.to_frb and that<br>
> didn't work either.<br>
><br>
> ---------------------------------------------------------------------------<br>
> AttributeError                            Traceback (most recent call last)<br>
> <ipython-input-17-e68719d58ae4> in <module>()<br>
> ----> 1 frb = FixedResolutionBuffer(slc, (0.0, 1.0, 0.0, 1.0), (1024,1024))<br>
>       2 plt.imshow(frb['Density'])<br>
>       3 plt.savefig('test_figure.png')<br>
>       4<br>
>       5<br>
><br>
> /Users/kde/yt-x86_64/src/yt-hg/yt/visualization/fixed_resolution.pyc in<br>
> __init__(self, data_source, bounds, buff_size, antialias, periodic)<br>
>      89         self.antialias = antialias<br>
>      90         self.data = {}<br>
> ---> 91         self.axis = data_source.axis<br>
>      92         self.periodic = periodic<br>
>      93<br>
><br>
> AttributeError: 'SlicePlot' object has no attribute 'axis'<br>
><br>
<br>
</div>Ah, this one we can fix.  Here what the FRB wants is actually the<br>
slice itself, not the slice plot.  There are two ways to do this.  The<br>
first is to grab the *existing* slice object:<br>
<br>
sl = slc.data_source<br>
<br>
and feed sl into a FixedResolutionBuffer creation.  But I think, since<br>
you're going to avoid all of the slice plot machinery altogether, it'd<br>
probably make more sense to take control of it with the data object<br>
machinery directly.  So you can create a slice, which is a data<br>
source, like this:<br>
<br>
sl = pf.h.slice(2, pf.domain_center[2])<br>
<br>
What I'm doing here is saying axis 2 (z) and at the z-th coordinate of<br>
the domain center.  Now if we query sl, we get all of the data points;<br>
this isn't what we want, since they are all different resolutions, so<br>
we use the FRB.  sl objects have a handy way of making FRBs:<br>
<br>
sl.to_frb( ...<br>
<br>
this takes a width (which can be a tuple), a resolution, and<br>
optionally a height.  help(sl.to_frb) will show the arguments and an<br>
example.  Now the FRB can be queried like you would a data object, and<br>
it gives back (N,N) arrays.  Hope that helps, and let us know!<br>
<br>
-Matt<br>
<br>
PS Those are some gorgeous simulation results, by the way.<br>
<div class="im"><br>
> THanks in advance for any help.<br>
> cheers<br>
> kathy<br>
><br>
><br>
> --<br>
> Kathy DeGioia Eastwood, Ph.D.<br>
> Professor of Physics and Astronomy<br>
> Northern Arizona University<br>
> Flagstaff, AZ 86011-6010<br>
> Ph: <a href="tel:928-523-7159" value="+19285237159">928-523-7159</a>   FX: <a href="tel:928-523-1371" value="+19285231371">928-523-1371</a><br>
> <a href="mailto:Kathy.Eastwood@nau.edu">Kathy.Eastwood@nau.edu</a><br>
> deliveries: 602 S. Humphreys St., Bldg 19 Rm 209<br>
><br>
</div>> _______________________________________________<br>
> yt-users mailing list<br>
> <a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
><br>
</blockquote></div><br><br clear="all"><br>-- <br>Kathy DeGioia Eastwood, Ph.D.<br>Professor of Physics and Astronomy<br>Northern Arizona University<br>Flagstaff, AZ 86011-6010<br>Ph: 928-523-7159   FX: 928-523-1371<br><a href="mailto:Kathy.Eastwood@nau.edu" target="_blank">Kathy.Eastwood@nau.edu</a><br>
deliveries: 602 S. Humphreys St., Bldg 19 Rm 209
</div>