【发布时间】: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