Open RicardaBeckmann opened 5 years ago
A quick work-around I have found for now:
Create two identical projections, one with the full dataset and one with the cut region. Then use the data_source of the full projection to create the contours for the cut_region.
#Load data
ds=yt.load('ramses_sink_00016/output_00016/info_00016.txt')
ad=ds.all_data()
cut_region=ad.cut_region("obj['velocity_magnitude']>5E6")
#Make two identical projections with different data sources
contour=yt.ProjectionPlot(ds, "x", "velocity_magnitude", center="max",data_source=ad)
image=yt.ProjectionPlot(ds, "x", "velocity_magnitude", center="max",data_source=cut_region)
#Plot contours on the second plot using the data source from the first
image.annotate_contour('density',data_source=contour.data_source)
Make sure the two projections are identical, except for the data source! Otherwise the contours won't line up with the original plot.
Density contours over a cut region based on the velocity:
Here is what the same plot looks like without supplying a data source: as expected, only density data contained within the cut region is used for contouring.
ds=yt.load('ramses_sink_00016/output_00016/info_00016.txt')
image=yt.ProjectionPlot(ds, "x", "velocity_magnitude", center="max")
image.annotate_contour('density')
Thanks for the detailed report! It's thanksgiving holiday here in the US so we may not be able to get to this until next week,
Bug report
Bug summary
When explicitly passing a data source to the annotate_contour callback, the code produces an error. This even happens if the data source is the same as the one originally used for the plot, let alone when it is a different data source (such as overplotting contours from all_data over a cut region projection, or similar)
Code for reproduction
Actual outcome
Expected outcome
I expect the code to simply overplot the temperature contours over the plot, as it would have done if no data_source had been passed explicitly.
Version Information
Comment
I'd like to fix this bug but am struggling to think of a sensible solution. As far as I can tell, the problem is that annotate_contour explicitly uses the fields 'px' and 'py', which are plot-specific and only set for the data_source actually attached to the plot.
How do I calculate these fields, for the existing plot but the new data_source?
This is the section of code in visulizations/plot_modifications.py that is giving trouble: