它是一个由 seaborn 热图组成的 3x3 Gridspec 矩阵,其中一个颜色条占据了整个第三列。我想让颜色条看起来更短。在我看来,有两种选择:
一种。要么我使颜色条的图更短
湾 我设法减少了 gridspec 中最后一列的可用空间。
不幸的是,我还没有找到合适的方法来做到这一点。有人可以帮助我吗?为了清楚起见,这里的代码。非常感谢您提前。
fig=plt.figure(figsize=(10,10))
gs = gridspec.GridSpec(2, 3, width_ratios=[1,1,0.1], height_ratios=[1,1])
gs.update(left=0.1, right=0.95, wspace=0.2, hspace=0.4)
#(0,0) PLOT
axh=plt.subplot( gs[0,0] )
sns.heatmap(M11,cmap="RdBu_r",cbar=False,linewidths=.5,xticklabels=True,yticklabels=True)
axh.set_xlabel('x_axis',fontsize=15);
axh.set_ylabel('y_axis',fontsize=15)
#(0,1) PLOT
ax0=plt.subplot( gs[0,1] )
sns.heatmap(M12,vmin=0,vmax=1,annot=False,cmap="RdBu_r",cbar=False,linewidths=.5,xticklabels=True,yticklabels=False)
ax0.set_xlabel('x_axis',fontsize=15);
#(1,0) PLOT
axh1=plt.subplot( gs[1,0],sharex=axh )
sns.heatmap(M21,cmap="RdBu_r",cbar=False,linewidths=.5,xticklabels=True,yticklabels=True)
axh1.set_xlabel('x_axis',fontsize=15);
axh1.set_ylabel('y_axis',fontsize=15)
#(1,1) PLOT
ax3=plt.subplot( gs[1,1] )
sns.heatmap(M22,vmin=0,vmax=1,annot=False,cmap="RdBu_r",cbar=False,linewidths=.5,xticklabels=True,yticklabels=False)
ax3.set_xlabel('x_axis',fontsize=15);
#(:,4) PLOT: COLORBAR
ax6=plt.subplot(gs[:,2] )
cb1 = matplotlib.colorbar.ColorbarBase(ax6, cmap="RdBu_r")
Run Code Online (Sandbox Code Playgroud)
小智 5
您不需要在额外的子图网格中绘制颜色条
我建议看这里:https : //matplotlib.org/3.1.1/gallery/axes_grid1/demo_colorbar_with_inset_locator.html
您可以绘制颜色条,如:
fig = plt.figure(figsize=(6, 6))
grid = plt.GridSpec(4, 4, hspace=0, wspace=0)
main_ax = fig.add_subplot(grid[:-1, 1:])
y_hist = fig.add_subplot(grid[:-1, 0])
x_hist = fig.add_subplot(grid[-1, 1:]
im = main_ax.imshow(array, **kwags) # <- your plots here
y_hist.plot(x,y)
x_hist.plot(x,y)
axins = inset_axes(x_hist, # here using axis of the lowest plot
width="5%", # width = 5% of parent_bbox width
height="340%", # height : 340% good for a (4x4) Grid
loc='lower left',
bbox_to_anchor=(1.05, 0.3, 1, 1),
bbox_transform=x_hist.transAxes,
borderpad=0,
)
cb = fig.colorbar(im, cax=axins)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1826 次 |
| 最近记录: |