简体   繁体   English

使用 AxesGrid 不匹配面板图的轴刻度和刻度标签

[英]Unmatching axes ticks and tick labels for a panel plot using AxesGrid

I'm trying to make a panel plot using mpl_toolkits.axes_grid1 .我正在尝试使用mpl_toolkits.axes_grid1制作面板图。 It has three rows and 2 columns and the code is the:它有三行和 2 列,代码是:

import os
import yt
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.axes_grid1 import AxesGrid

fig=plt.figure()
grid= AxesGrid(fig, (0.075,0.075,0.85,0.85), nrows_ncols = (3,2), axes_pad = 0.5,
               label_mode="L",share_all = True, direction='row', cbar_location="right",
               cbar_mode="edge", cbar_size="5%", cbar_pad="0.0%", aspect=True)
loc='/share/Part1/guido/mc_evolution/bouchut/'
folder=['cond_0_amr/','cond_0_h/']
snap_bn='mc_evolution_hdf5_plt_cnt_'

snap_1=[25,50,96]
snap_2=[25,50,130]

snap_d={'0':snap_1,'1':snap_2}

property='density'
color_map='rainbow'
zmin=2.12e-22
zmax=1e-19
axis="z"
log_norm_vel=False
max_dens=np.zeros(len(snap_1))
min_dens=np.zeros(len(snap_1))

for i in range(len(folder)):
    for k,j in enumerate(snap_d[str(i)]):
        index=2*k+i
        ds=yt.load(loc+folder[i]+snap_bn+str(j).zfill(4))
        p=yt.SlicePlot(ds, axis,property,center='c')
        slc=ds.slice(axis,0.5)
        p_fdr=slc.to_frb((5,'pc'),1024)
        max_dens[k]=p_fdr['dens'].max()
        min_dens[k]=p_fdr['dens'].min()
        p.antialias = True
        p.set_log(property,True)#,linthresh=None)
        p.set_minorticks('all','on')
        p.set_cbar_minorticks('all','on')
        p.zoom(2.0)
        p.annotate_velocity(factor=25, normalize=log_norm_vel, 
                            plot_args={"color":'g', 'headwidth':10, 'headlength':8})
        p.annotate_timestamp(corner='upper_left', draw_inset_box=False, 
                             text_args={'fontsize':'x-small','color':'w'})
        plot = p.plots['density']
        plot.figure = fig
        plot.axes = grid[index].axes
        plot.cax = grid.cbar_axes[index]
        plot.cax.minorticks_on()
        p._setup_plots()

plt.savefig('panel_collapse_evol_3v2_2_sims_each_'+color_map+'.png')

The figure I get is the following:我得到的数字如下:

在此处输入图片说明

The problem is with the x-axis of the right bottom plot, it is not showing the same axis ticks labels, it just show -2, 0, and 2 instead of -2,-1,0,1,2 like the bottom left plot.问题在于右下图的 x 轴,它没有显示相同的轴刻度标签,它只显示 -2、0 和 2 而不是像底部一样的 -2,-1,0,1,2左图。 I don't know what may be causing this.我不知道是什么原因造成的。 Could you please help me?请你帮助我好吗?

I guess the colorbar being so close interferes with the automatic tick label choices.我猜颜色条如此接近会干扰自动刻度标签选择。 You could label them manually, but since the colorbar is the same for all subplots, a better approach would be to plot just one larger separate colorbar.您可以手动标记它们,但由于所有子图的颜色条都相同,因此更好的方法是仅绘制一个更大的单独颜色条。 Here is an example of how to do this: Matplotlib Gallery以下是如何执行此操作的示例: Matplotlib Gallery

By the way, rainbow is not a good choice to map a continuous variable, because it is not a sequential colormap.顺便说一下, rainbow不是映射连续变量的好选择,因为它不是顺序颜色图。 Better use the default viridis .最好使用默认的viridis This is discussed here: Choosing Colormaps这在这里讨论:选择颜色图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM