How can I provide either the cax argument to use as the Axes for the Colorbar, or provide the ax argument to steal space from it, or add mappable to an Axes. Although I can plot my chart successfully, I can’t avoid the warning. Any help you render would be much appreciated. Thank you very much.
My codes:
# plot chart based on predicted value
fig, ax = plt.subplots()
colorsMap = 'jet'
cm = plt.get_cmap(colorsMap)
cNorm = matplotlib.colors.Normalize(vmin=min(yhat), vmax=max(yhat))
scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=cm)
ax.scatter(Y, yhat, c=scalarMap.to_rgba(yhat), s=2, alpha=0.7)
scalarMap.set_array(yhat)
fig.colorbar(scalarMap)
ax.set_xlabel('Actual')
ax.set_ylabel('Predicted')
ax.text(0.85, 0.5, 'R^2=0.76', horizontalalignment='center', verticalalignment='center', transform=ax.transAxes)
# add diagonal line
ident = [np.min(Y), np.max(Y)]
plt.plot(ident, ident, color='red')
# save yhat plot
plt.savefig('Predicted.png', dpi=600)
I think you just need to pass ax=ax in your call to colorbar. That tells it that you want to make your main axes a little smaller to make space for the color bar.
I think you just need to pass ax=ax in your call to colorbar. That tells it that you want to make your main axes a little smaller to make space for the color bar.