The following code fails to run on Python 2.5.4:
from matplotlib import pylab as pl
import numpy as np
data = np.random.rand(6,6)
fig = pl.figure(1)
fig.clf
I found another solution to this problem in a tutorial.
The code below, will work well for the plt.imshow() method:
def colorbar(Mappable, Orientation='vertical', Extend='both'):
Ax = Mappable.axes
fig = Ax.figure
divider = make_axes_locatable(Ax)
Cax = divider.append_axes("right", size="5%", pad=0.05)
return fig.colorbar(
mappable=Mappable,
cax=Cax,
use_gridspec=True,
extend=Extend, # mostra um colorbar full resolution de z
orientation=Orientation
)
fig, ax = plt.subplots(ncols=2)
img1 = ax[0].imshow(data)
colorbar(img1)
img2 = ax[1].imshow(-data)
colorbar(img2)
fig.tight_layout(h_pad=1)
plt.show()
It may not work well with other plotting methods. For example, it did not work with Geopandas Geodataframe plot.