bigbug
bigbug

Reputation: 59444

How to shift the colorbar position to right

I draw a scatter chart as below : enter image description here

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 ?

Upvotes: 8

Views: 25761

Answers (2)

Zipo
Zipo

Reputation: 393

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) ## 

Upvotes: 13

Robbert
Robbert

Reputation: 2724

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".

Upvotes: 19

Related Questions