matplotlib在所有ImageGrid轴上打勾

时间:2018-06-26 15:13:31

标签: python-3.x matplotlib visualization

有没有一种方法可以显示ImageGrid图中所有x轴的刻度?

例如,在我的输出中,我仅在底行获得报价。我想在第一行也有刻度(数据范围不一定相同)

from mpl_toolkits.axes_grid1 import ImageGrid

fig = plt.figure(figsize=(24, 14))
grid = ImageGrid(fig, 111,          
                 nrows_ncols=(2,4),
                 axes_pad=0.5,
                 share_all=False,
                 cbar_location="right",
                 cbar_mode="single",
                 cbar_size="5%",
                 cbar_pad=0.25,
                 )
adjustment = len(grid)
for i, j in enumerate(distance_matrices):
    im = plot_distance_matrix(distance_matrices[j],fechas[j],titulos[i], grid[i])
    im = plot_distance_matrix(distance_matrices_d[j],fechas_d[j],titulos_d[i], grid[i+int(0.5*adjustment)])

grid[-1].cax.colorbar(im)
grid[-1].cax.toggle_label(True)
plt.show()

enter image description here

1 个答案:

答案 0 :(得分:0)

答案是设置参数label_mode =“ all”

from mpl_toolkits.axes_grid1 import ImageGrid
fig = plt.figure(figsize=(24, 14))
grid = ImageGrid(fig, 111,          
                 nrows_ncols=(2,4),
                 axes_pad=0.5,
                 share_all=False,
                 cbar_location="right",
                 cbar_mode="single",
                 cbar_size="5%",
                 cbar_pad=0.25,
                 label_mode="all")
adjustment = len(grid)
for i, j in enumerate(distance_matrices):
    im = plot_distance_matrix(distance_matrices[j],fechas[j],titulos[i], grid[i])
    im = plot_distance_matrix(distance_matrices_d[j],fechas_d[j],titulos_d[i], grid[i+int(0.5*adjustment)])

grid[-1].cax.colorbar(im)
grid[-1].cax.toggle_label(True)
plt.show()