Exemple de comment avoir une figure matplotlib avec deux colorbars (exemple inspiré du code source suivant)
On a ici de plus ajusté la taille de la colorbar à la figure (voir)
from mpl_toolkits.axes_grid1 import make_axes_locatable
from numpy.ma import masked_array
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.cm as cm
v1 = -1+2*np.random.rand(20,20)
v1a = masked_array(v1,v1<0)
v1b = masked_array(v1,v1>=0)
fig,ax = plt.subplots()
pa = ax.imshow(v1a,interpolation='nearest',cmap=cm.Reds)
pb = ax.imshow(v1b,interpolation='nearest',cmap=cm.winter)
plt.xlabel('Day')
plt.ylabel('Depth')
plt.title('Matplotlib imshow with two colormaps')
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.3)
cba = plt.colorbar(pa, cax=cax)
cax = divider.append_axes("right", size="5%", pad=1.0)
cbb = plt.colorbar(pb, cax=cax)
cba.set_label('positive')
cbb.set_label('negative')
plt.savefig("matplotlib_two_colormaps.png", bbox_inches='tight')
plt.show()
Références
Liens | Site |
---|---|
Two different color colormaps in the same imshow matplotlib | stackoverflow |
Join two colormaps in imshow | stackoverflow |
Set two matplotlib imshow plots to have the same color map scale | stackoverflow |
mpl_toolkits.axes_grid.axes_divider | matplotlib doc |
matplotlib: Using append_axes multiple times | stackoverflow |
matplotlib colorbar placement and size | stackoverflow |
Set Matplotlib colorbar size to match graph | stackoverflow |