更好地控制颜色栏位置的最佳方法是为其提供自己的轴。像这样:# What I imagine your plotting looks like so farfig = plt.figure()ax1 = fig.add_subplot(111)ax1.plot(your_data)# Now adding the colorbarcbaxes = 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的分数。