[yt-users] Overlaying matplotlib plots on yt plots

DORIS LEE dorislee at berkeley.edu
Tue Jun 2 13:02:51 PDT 2015


Hi Suoqing, Nathan,

The annotate_sphere works perfect here!
Also, thanks for pointing me to FRBs, this should be helpful when I make
future yt plots.

Doris

On Mon, Jun 1, 2015 at 9:23 PM, Nathan Goldbaum <nathan12343 at gmail.com>
wrote:

>
>
> On Mon, Jun 1, 2015 at 9:13 PM, DORIS LEE <dorislee at berkeley.edu> wrote:
>
>> Hi all,
>>
>> I have been trying to plot a circle of a given radius around the boundary
>> of a collapsing cloud to track its evolution.
>> Usually in matplotlib, I would just draw a circle using a xy meshgrid,
>> but if I do this using matplotlib the circle would be on a separate figure
>> and not overlaid on the yt plot. So I tried using a PlotWindow to separate
>> the data and the yt plot  but I get this error:
>>
>> In [92]:yt.visualization.plot_window.PlotWindow(proj,(-1e5,1e5,-1e5,1e5))
>>
>> AttributeError: 'ProjectionPlot' object has no attribute '_key_fields'
>>
>>
> PlotWindow is a base class for the other plot objects, and it should never
> be instantiated directly.  We could probably add some logic so the error
> here is less obscure just in case a future user gets confused and tries to
> do this.
>
>
>> In general, is there to get my RAMSES data loaded into yt as a numpy
>> array with actual numbers in them then feed it into matplotlib to do this
>> task? or alternatively, is there a simpler way to do this directly on yt
>> using annotate_contour or some other yt function?
>>
>> Thank you.
>>
>> Regards,
>> Doris
>> ----
>> Code for generating the attached plot, the green boundary line is in
>> theory what I am trying to draw.
>>
>> ds= yt.load("../../bin/output_00002/info_00002.txt")
>> proj = yt.ProjectionPlot(ds, "y", "density",window_size=10)
>> proj.set_cmap("density","rainbow")
>> proj.annotate_velocity()
>> proj.show()
>>
>
> Have you seen the sphere callback?
>
>
> http://yt-project.org/docs/dev/visualizing/callbacks.html#overplot-a-circle-on-a-plot
>
> You can also access the matplotlib figure and axes object that the
> ProjectionPlot wraps:
>
>
> http://yt-project.org/docs/dev/cookbook/simple_plots.html#accessing-and-modifying-plots-directly
>
> Additionally, if you want the raw data to create the plot yourself using
> matplotlib, plot objects have an "frb" attribute (short for
> FixedResolutionBuffer) you can use to get the raw image you can pass to
> matplotlib's imshow function.  In the above script, you should be able to
> do something like:
>
>     dens = proj.frb['density']
>
>     print dens.shape
>     print dens.units
>
>     # strip units to pass to matplotlib
>     dens = np.array(dens)
>
>     plt.imshow(dens)
>
> You can also create a FixedReslutionBuffer without creating a plot object
> first:
>
>
> http://yt-project.org/docs/dev/quickstart/data_objects_and_time_series.html?highlight=frb
>
> (this is actually how the PlotWindow class is implemented internally).
>
> Hope that's helpful,
>
> Nathan
>
>
>> _______________________________________________
>> yt-users mailing list
>> yt-users at lists.spacepope.org
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>
>>
>
> _______________________________________________
> 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/20150602/4f4baadc/attachment.htm>


More information about the yt-users mailing list