【问题标题】:Colorbar axis label overlapping with ticks Matplotlib颜色条轴标签与刻度重叠 Matplotlib
【发布时间】:2020-01-05 04:22:45
【问题描述】:

我正在使用 Matplotlib 在右侧绘制带有颜色条的散点图。颜色栏的标签与刻度重叠/太接近。

我使用了以下代码。


plt.figure(figsize=(10,10))
plt.title('Spatio-temporal variations of Mean Absolute Error',fontsize=15)
plt.scatter(df['longitude'], df['latitude'], c = df['mean_abs_error'], cmap = 'rainbow')
plt.ylabel('Longitude', fontsize = 15)
plt.xlabel('Latitude', fontsize = 15)
plt.xticks(fontsize = 15)
plt.yticks(fontsize = 15)
plt.colorbar().ax.set_ylabel('Mean Absolute Error', rotation=270, fontsize = 15)


我希望颜色条“平均绝对误差”的标签稍微靠右一点,即在轴刻度和轴标签之间引入一些间距。

【问题讨论】:

    标签: python matplotlib colorbar


    【解决方案1】:

    使用标签板:

    plt.colorbar().ax.set_ylabel('Mean Absolute Error', rotation=270, fontsize = 15, labelpad=15)
    

    【讨论】:

      猜你喜欢
      • 2012-03-14
      • 2019-05-11
      • 2016-06-14
      • 2020-02-18
      • 2021-01-31
      • 2012-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多