我该如何修复这个情节?
我想要:
- 两个颜色条不重叠。
- 使它们的高度等于绘图。
这是我的代码:
combined = (...) # some irrelevant to question data praparation - this variable contain square matrix with RGBA chanels
plt.figure(dpi=300, figsize=(2.1,1.9))
gs = gridspec.GridSpec(1, 3, width_ratios=[20,1,1])
ax1 = plt.subplot(gs[0])
ax2 = plt.subplot(gs[1])
ax3 = plt.subplot(gs[2])
cax = ax1.imshow(combined, interpolation="None")
mpl.colorbar.ColorbarBase(ax2, cmap=cmap_top, norm=norm_top)
mpl.colorbar.ColorbarBase(ax3, cmap=cmap_top, norm=norm_top)
我使用的是 python 3.6 和 matplotlib 2.0。
最佳答案
对于问题 1,我会考虑两种可能性: A。修改控制图形之间水平间距的 wspace 参数,即:
gs = gridspec.GridSpec(1, 3, width_ratios=[20,1,1])
gs.update(wspace=0.05)
b.在第一个和第二个颜色条之间添加一个额外的列,充当一些空白空间:
gs = gridspec.GridSpec(1, 4, width_ratios=[20,1,0.15,1])
对于问题 2,我会用不同的方式写:
ax2=plt.subplot(gs[0,1] )
cb1 = matplotlib.colorbar.ColorbarBase(ax2, cmap="RdBu_r")
希望对你有帮助!
关于python - 如何使用 gridspec 调整列宽?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43804513/