height of colorbar (matplotlib)
Question:
Is it possible to have a colorbar smaller than the height of figure?
I know that we can adjust the size of colorbar with
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="3%", pad=0.05)
pl.colorbar(im, cax=cax)
size
only adjust the width of colorbar. but how about the height?
I am looking for a colorbar at upper right, with the half height of the figure.
Answers:
You can use fig.add_axes
and fine-tune the parameters as you wish:
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import numpy as np
fig = plt.figure()
ax = plt.subplot(111)
im = ax.imshow(np.arange(100).reshape((10, 10)))
c = plt.colorbar(im, cax = fig.add_axes([0.78, 0.5, 0.03, 0.38]))
Is it possible to have a colorbar smaller than the height of figure?
I know that we can adjust the size of colorbar with
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="3%", pad=0.05)
pl.colorbar(im, cax=cax)
size
only adjust the width of colorbar. but how about the height?
I am looking for a colorbar at upper right, with the half height of the figure.
You can use fig.add_axes
and fine-tune the parameters as you wish:
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import numpy as np
fig = plt.figure()
ax = plt.subplot(111)
im = ax.imshow(np.arange(100).reshape((10, 10)))
c = plt.colorbar(im, cax = fig.add_axes([0.78, 0.5, 0.03, 0.38]))