我有一个带有颜色条的matplotlib图。我想将颜色条定位为水平,并位于绘图下方。我几乎可以通过以下方式做到这一点:plt.colorbar(orientation="horizontal",fraction=0.07,anchor=(1.0,0.0))但是,颜色条仍与图略有重叠(以及x轴的标签)。我想进一步将颜色栏下移,但我不知道该怎么做。
2 回答

RISEBY
TA贡献1856条经验 获得超5个赞
更好地控制颜色栏位置的最佳方法是为其提供自己的轴。像这样:
# What I imagine your plotting looks like so far
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(your_data)
# Now adding the colorbar
cbaxes = fig.add_axes([0.8, 0.1, 0.03, 0.8])
cb = plt.colorbar(ax1, cax = cbaxes)
add_axes的方括号中的数字表示[left,bottom,width,height],其中坐标只是绘图区域从0到1的分数。
添加回答
举报
0/150
提交
取消