
Hi Nathan, Thanks! It seems though that the frb cannot be directly passed to matplotlib's imshow, though np.array(frb) can. 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. Regards, Jon On Tue, Aug 11, 2015 at 2:42 PM, <yt-users-request@lists.spacepope.org> wrote:
Date: Tue, 11 Aug 2015 13:17:50 -0500 From: Nathan Goldbaum <nathan12343@gmail.com> To: Discussion of the yt analysis package <yt-users@lists.spacepope.org> Subject: Re: [yt-users] getting slice array Message-ID: <CAJXewOmiymap0uUBy0hL= zo0Ltf0kG7UErXYFy9dqZseXoapsg@mail.gmail.com> Content-Type: text/plain; charset="utf-8"
On Tue, Aug 11, 2015 at 1:10 PM, Slavin, Jonathan <jslavin@cfa.harvard.edu
wrote:
Hi all,
I'm new to using yt, though I'm an experienced python and matplotlib user. I've been doing runs with FLASH and would like to be able to plot the results with matplotlib. I've used yt "interactively" in an ipython notebook and found it a bit cumbersome - e.g. you can't pan and zoom like you can with matplotlib. On the other hand yt has some nice facilities for accessing the data. So my question is, how do I get a slice, such as is plotted using the yt.SlicePlot function, in an array that I can then manipulate, plot, etc.? If I do: ds = yt.load(file) slc = ds.slice(2,0.) d = slc['density'] I have a YTArray that's apparently 1-D: d.shape (138496,) I should mention that this is a 2-D, cylindrically symmetric (r-z) run. Thanks in advance for any help you can offer.
If you have a yt plot object (e.g. a SlicePlot or a ProjectionPlot), you can do:
slc = yt.SlicePlot(...) densit_image = slc.frb['density']
"frb" here is a FixedResolutionBuffer object which translates the multiresolution 1-D array you ran into above into a 2D pixelized representation of your data.
You can also create a FixedResolutionBuffer object directly:
http://yt-project.org/docs/dev/analyzing/generating_processed_data.html#d-im...
The image arrays you get back from a FixedResolutionBuffer object can be passed directly to e.g. matplotlib's imshow command.
By the way, Matt Turk has an open pull request to add the interactive panning and zooming you were looking for:
http://yt-project.org/docs/dev/analyzing/generating_processed_data.html#d-im...
I'm hoping to finish up that pull request soon, since having interactive plots both in the notebook and using matplotlib's interactive backends is a common feature request.
-- ________________________________________________________ Jonathan D. Slavin Harvard-Smithsonian CfA jslavin@cfa.harvard.edu 60 Garden Street, MS 83 phone: (617) 496-7981 Cambridge, MA 02138-1516 cell: (781) 363-0035 USA ________________________________________________________