【问题标题】:How to set distance between colorbar and its label [duplicate]如何设置颜色条与其标签之间的距离[重复]
【发布时间】:2021-08-23 20:21:16
【问题描述】:

我遇到了重叠颜色条及其标签的问题,如下所示:

代码:

import matplotlib.pyplot as plt

true = [1,2,3,4,5,6,7,8,9,10]
pred = [1.02, 2.1, 2.99, 4, 5.01, 5.98, 7, 8.1, 9, 10.1]
std = [0.001, 0.002, 0.002, 0.001, 0.003, 0.004, 0.004, 0.001, 0.002, 0.004]

   
fig = plt.figure(figsize=(6,6))
ax = fig.add_subplot(1,1,1)
cmap = 'coolwarm'
my_plot = ax.scatter(true, pred, c=std, cmap=cmap, edgecolors='black', lw=1)
ax.set_xlabel('Observed', fontsize=18)
ax.set_ylabel('Predicted', fontsize=18)
cbar = fig.colorbar(my_plot)
cbar.set_label('standard deviation', rotation=270)
plt.axis('equal') 

有什么方法可以增加颜色条与其标签之间的距离?

【问题讨论】:

  • 使用labelpadcbar.set_label('standard deviation', rotation=270, labelpad=15)

标签: python matplotlib label colorbar


【解决方案1】:

只需在标签上添加 pad :

cbar.set_label('standard deviation', rotation=270, labelpad=15)

结果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-25
    • 2010-12-10
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    相关资源
    最近更新 更多