I draw a scatter chart as below :
The code is :
sc = plt.scatter(x, y, marker='o', s=size_r, c=clr, vmin=lb, vmax=ub, cmap=mycm, alpha=0.65)
cbar = plt.colorbar(sc, shrink=0.9)
And I want to shift the colorbar to right a little bit to extend the drawing area. How to do that ?
To move the colorbar to a different tile, set the Layout property of the colorbar. To display the colorbar in a location that does not appear in the table, use the Position property to specify a custom location. If you set the Position property, then MATLAB sets the Location property to 'manual' .
The colorbar() function in pyplot module of matplotlib adds a colorbar to a plot indicating the color scale.
Use the pad
attribute.
cbar = plt.colorbar(sc, shrink=0.9, pad = 0.05)
The documentation of make_axes() describes how to use pad
: "pad: 0.05 if vertical, 0.15 if horizontal; fraction of original axes between colorbar and new image axes".
Actually you can put the colorbar anywhere you want.
fig1=figure()
sc = plt.scatter(x, y, marker='o', s=size_r, c=clr, vmin=lb, vmax=ub, cmap=mycm, alpha=0.65)
position=fig1.add_axes([0.93,0.1,0.02,0.35]) ## the parameters are the specified position you set
fig1.colorbar(sc,cax=position) ##
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With