<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 11, 2015 at 2:01 PM, Slavin, Jonathan <span dir="ltr"><<a href="mailto:jslavin@cfa.harvard.edu" target="_blank">jslavin@cfa.harvard.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div style="font-family:arial,helvetica,sans-serif">​Hi Nathan,</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">Thanks!  It seems though that the frb cannot be directly passed to matplotlib's imshow, though np.array(frb) can.</div></div></div></blockquote><div><br></div><div>Just to be clear, the FRB is the object that creates the image buffers, so you would np.array(frb['density']) to create an ndarray representation of the 2D density image. I think you should be able to pass the YTArray with units to imshow as well, at least on relatively recent versions of matplotlib. Most matplotlib plotting functions just strip units from arrays passed to it, although you're right that sometimes it is necessary to cast to ndarray.</div><div><br></div><div>You can also use the .value or .ndview properties of any YTArray object to get back a copy of the array cast to ndarray or an ndarray "view" into the original array, respectively.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">I would like it in general if yt could provide simpler means of accessing arrays or array-like objects such as are plotted up.  There are many reasons for this besides the desire to plot using matplotlib -- e.g. to create plots of ratios of quantities, or to plot scaled variables.​  Perhaps this is possible now, though it's not obvious from the docs.</div></div></div></blockquote><div><br></div><div>Did you take a look at the page I linked to earlier?</div><div><br></div><div><a href="http://yt-project.org/docs/dev/analyzing/generating_processed_data.html">http://yt-project.org/docs/dev/analyzing/generating_processed_data.html</a><br></div><div><br></div><div>That page is focused on generating processed data (e.g. images and histograms) that can be passed to matplotlib. In fact, that's how all of the one-liner plot recipes yt shows in the docs work behind the scenes.</div><div><br></div><div>Is there something we should expand on in that page?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">Regards,</div><div style="font-family:arial,helvetica,sans-serif">Jon</div><br><div class="gmail_quote">On Tue, Aug 11, 2015 at 2:42 PM,  <span dir="ltr"><<a href="mailto:yt-users-request@lists.spacepope.org" target="_blank">yt-users-request@lists.spacepope.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="overflow:hidden">Date: Tue, 11 Aug 2015 13:17:50 -0500<br>
From: Nathan Goldbaum <<a href="mailto:nathan12343@gmail.com" target="_blank">nathan12343@gmail.com</a>><br>
To: Discussion of the yt analysis package<br>
        <<a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a>><br>
Subject: Re: [yt-users] getting slice array<br>
Message-ID:<br>
        <CAJXewOmiymap0uUBy0hL=<a href="mailto:zo0Ltf0kG7UErXYFy9dqZseXoapsg@mail.gmail.com" target="_blank">zo0Ltf0kG7UErXYFy9dqZseXoapsg@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<div><div class="h5"><br>
<br>
On Tue, Aug 11, 2015 at 1:10 PM, Slavin, Jonathan <<a href="mailto:jslavin@cfa.harvard.edu" target="_blank">jslavin@cfa.harvard.edu</a>><br>
wrote:<br>
<br>
> Hi all,<br>
><br>
> I'm new to using yt, though I'm an experienced python and matplotlib<br>
> user.  I've been doing runs with FLASH and would like to be able to plot<br>
> the results with matplotlib.  I've used yt "interactively" in an ipython<br>
> notebook and found it a bit cumbersome - e.g. you can't pan and zoom like<br>
> you can with matplotlib.  On the other hand yt has some nice facilities for<br>
> accessing the data.  So my question is, how do I get a slice, such as is<br>
> plotted using the yt.SlicePlot function, in an array that I can then<br>
> manipulate, plot, etc.?  If I do:<br>
> ds = yt.load(file)<br>
> slc = ds.slice(2,0.)<br>
> d = slc['density']<br>
> I have a YTArray that's apparently 1-D:<br>
> d.shape<br>
> (138496,)<br>
> I should mention that this is a 2-D, cylindrically symmetric (r-z) run.<br>
> Thanks in advance for any help you can offer.<br>
><br>
<br>
If you have a yt plot object (e.g. a SlicePlot or a ProjectionPlot), you<br>
can do:<br>
<br>
slc = yt.SlicePlot(...)<br>
densit_image = slc.frb['density']<br>
<br>
"frb" here is a FixedResolutionBuffer object which translates the<br>
multiresolution 1-D array you ran into above into a 2D pixelized<br>
representation of your data.<br>
<br>
You can also create a FixedResolutionBuffer object directly:<br>
<a href="http://yt-project.org/docs/dev/analyzing/generating_processed_data.html#d-image-arrays" rel="noreferrer" target="_blank">http://yt-project.org/docs/dev/analyzing/generating_processed_data.html#d-image-arrays</a><br>
<br>
The image arrays you get back from a FixedResolutionBuffer object can be<br>
passed directly to e.g. matplotlib's imshow command.<br>
<br>
By the way, Matt Turk has an open pull request to add the interactive<br>
panning and zooming you were looking for:<br>
<br>
<a href="http://yt-project.org/docs/dev/analyzing/generating_processed_data.html#d-image-arrays" rel="noreferrer" target="_blank">http://yt-project.org/docs/dev/analyzing/generating_processed_data.html#d-image-arrays</a><br>
<br>
I'm hoping to finish up that pull request soon, since having interactive<br>
plots both in the notebook and using matplotlib's interactive backends is a<br>
common feature request.<br></div></div></div></blockquote></div><br><br><br clear="all"><span class=""><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr">________________________________________________________<br>Jonathan D. Slavin                 Harvard-Smithsonian CfA<br><a href="mailto:jslavin@cfa.harvard.edu" target="_blank">jslavin@cfa.harvard.edu</a>       60 Garden Street, MS 83<br>phone: <a href="tel:%28617%29%20496-7981" value="+16174967981" target="_blank">(617) 496-7981</a>       Cambridge, MA 02138-1516<br>cell: <a href="tel:%28781%29%20363-0035" value="+17813630035" target="_blank">(781) 363-0035</a>             USA<br>________________________________________________________<br><br></div></div></div></div>
</span></div></div>
<br>_______________________________________________<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" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br></div></div>