samedi 25 octobre 2014

matplotlib imshow fixed aspect and vertical colorbar matching master axis height


Vote count:

0




I need to plot a mesh grid with "temperature map" values, currently I'm using imshow, with a colormap. This is described in the Matplotlib overview, so I modified the example to force custom aspect of the figure:



import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import numpy as np

plt.figure()
ax = plt.gca()
im = ax.imshow(np.arange(100).reshape((10,10)), aspect=0.5)

# create an axes on the right side of ax. The width of cax will be 5%
# of ax and the padding between cax and ax will be fixed at 0.05 inch.
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)

plt.colorbar(im, cax=cax)

plt.savefig("test.png")


But the result is not what I want, the colorbar is higher than the master axis. Interestingly, when the colormap is horizontal, it is scaled properly:



cax = divider.append_axes("bottom", size="5%", pad=0.05)
plt.colorbar(im, cax=cax, orientation="horizontal")


asked 1 min ago

jlk

1






matplotlib imshow fixed aspect and vertical colorbar matching master axis height

Aucun commentaire:

Enregistrer un commentaire