In [ ]:
%matplotlib inline
import yt
import logging
logging.getLogger('yt').setLevel(logging.ERROR)
import numpy as np
import matplotlib
matplotlib.rcParams['font.family'] = 'stixgeneral'
matplotlib.rcParams['savefig.dpi'] = 150
import matplotlib.pyplot as plt
import os
from mpl_toolkits.axes_grid1 import AxesGrid

In [ ]:
dirs = ['/home/ychen/data/0only_0605_hinf/',\
        '/home/ychen/data/0only_0529_h1/',\
        '/home/ychen/data/0only_0605_h0/',\
        '/home/ychen/data/0only_0602_hydro/']

labels = ['toroidal', 'helical', 'poloidal', 'hydro']

proj_axis = 'x'
field = 'density'
center=(0.0,0.0,0.0)
fig = plt.figure()

grid = AxesGrid(fig, (0.075,0.075,0.85,0.85),
                nrows_ncols = (1, 4),
                axes_pad = 0.05,
                label_mode = "L",
                share_all = True,
                cbar_location="right",
                cbar_mode="single",
                cbar_size="5%",
                cbar_pad="0%")

for i, dir in enumerate(dirs):
    # Load the data and create a single plot
    ds = yt.load(os.path.join(dir, 'data/MHD_Jet_hdf5_plt_cnt_0630'))# load data
    p=yt.SlicePlot(ds, proj_axis, field, center=center, origin='center-domain',\
                              width=((40,'kpc'), (80,'kpc')),)
    # Ensure the colorbar limits match for all plots
    p.set_zlim('density', 3E-28, 2E-25)
    p.set_cmap(field, 'arbre')
    p.annotate_text((0.05, 0.95), labels[i], coord_system='axis', text_args={'color':'k'})
    p.set_buff_size((400,800))
    p.set_font_size(9)
    
    if i == 0:
        p.annotate_timestamp(0.70, 0.95, time_format="{time:6.2f} {units}", time_unit='Myr', text_args={'color':'k'})
    

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

    # Finally, this actually redraws the plot.
    p._setup_plots()
    p.plots[field].axes.set_xticks([-10,0,10,20])
    p.plots[field].axes.set_xticklabels([-10,0,10,20])

In [ ]:
for i, ax in enumerate(grid.axes_all):
    ax.tick_params(axis='x', color='grey')
    ax.tick_params(axis='y', color='grey')
    #ax.set_ylim(-6, 6)
    #ax.set_yticks([-5,0,5])
    #ax.set_yticklabels([-5,0,5])
    #ax.set_xlim(0,width[0].in_units('kpc').v)
    #ax.set_xticks(np.arange(0,50,5))
    #ax.set_xticklabels([0, '', 10, '', 20, '', 30, '', 40, ''])
    ax.minorticks_off()
    ax.tick_params(axis='x', color='grey')
    ax.tick_params(axis='y', color='grey')
    ax.grid(ls='--', alpha=0.5)
    if i == 0:
        ax.set_xlabel('y (kpc)')
        ax.set_ylabel('z (kpc)')
    else:
        ax.set_xlabel('y (kpc)')
        ax.set_ylabel('')
fig.set_figwidth(10)
fig.set_figheight(5)
fig.savefig('compare_4_density_630.pdf', bbox_inches='tight')
fig

In [ ]: