[yt-users] overplot grid structures (with .annotate_grids()) while using AxesGrid

Tim-Eric Rathjen rathjen at ph1.uni-koeln.de
Wed Oct 14 06:46:58 PDT 2015


Hi,
I'm trying to do some kind of a multiplot using yt and the 
.annotate_grids()-function provided with yt.

My code looks like this:

import yt
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import AxesGrid

fns = ['turb_vrms10_n3_pm__hdf5_plt_cnt_0200', 
'turb_vrms10_n3_pm__hdf5_plt_cnt_0300']

fig = plt.figure()

# See http://matplotlib.org/mpl_toolkits/axes_grid/api/axes_grid_api.html
# These choices of keyword arguments produce a four panel plot with a single
# shared narrow colorbar on the right hand side of the multipanel plot. Axes
# labels are drawn for all plots since we're slicing along different 
directions
# for each plot.
grid = AxesGrid(fig, (0.075,0.075,0.85,0.85),
                 nrows_ncols = (2, 1),
                 axes_pad = 0.05,
                 label_mode = "L",
                 share_all = True,
                 cbar_location="right",
                 cbar_mode="single",
                 cbar_size="3%",
                 cbar_pad="0%")

for i, fn in enumerate(fns):
     # Load the data and create a single plot
     ds = yt.load(fn) # load data

     # Make a ProjectionPlot with a width of 34 comoving megaparsecs
     p = yt.ProjectionPlot(ds, 'z', 'density').annotate_grids()
     #p = yt.SlicePlot(ds, 'z', 'density').annotate_grids()

     # Ensure the colorbar limits match for all plots
     #p.set_zlim('density', 1e-4, 1e-2)
     p.set_zlim('density', minVal, maxVal)

     # This forces the ProjectionPlot to redraw itself on the AxesGrid axes.
     plot = p.plots['density']
     plot.figure = fig
     plot.axes = grid[i].axes
     plot.cax = grid.cbar_axes[i]

     # Finally, this actually redraws the plot.
     p._setup_plots()

plt.savefig('multiplot_1x2_time_series.png', bbox_inches='tight')

And it works fine EXCEPT that it doesn't annotate the grid structure..
Any ideas somebody?

Thank you very much,
Best regards,
Tim-Eric



More information about the yt-users mailing list