简体   繁体   English

色标轴标签与刻度重叠Matplotlib

[英]Colorbar axis label overlapping with ticks Matplotlib

I am plotting a scatterplot with a colorbar on the right using Matplotlib. 我正在使用Matplotlib在右侧绘制带有颜色栏的散点图。 The labels of the colorbar get overlapped/get too close with the ticks. 色标的标签与刻度线重叠/太近。

I have used the following code. 我使用了以下代码。


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)


在此处输入图片说明

I wish to have the label of the colorbar 'Mean Absolute Error' a bit further to the right, ie introduce some spacing between the axis ticks and the axis label. 我希望颜色条“平均绝对误差”的标签在右边更远,即在轴刻度和轴标签之间引入一些间距。

使用标签:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM