I am plotting a scatterplot with a colorbar on the right using 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, i.e. introduce some spacing between the axis ticks and the axis label.
Use labelpad:
plt.colorbar().ax.set_ylabel('Mean Absolute Error', rotation=270, fontsize = 15, labelpad=15)