Reputation: 175
I would like to plot one subplot like:
Title 1
Fig1 Fig2 Fig3
With a common colorbar for these 3 figures (1,2,3).
Title2
Fig4 Fig5 Fig6
With a common colorbar for these 3 figures (4,5,6).
I haven't found a way to add two different colorbars on the same figure as described above.
Upvotes: 1
Views: 4032
Reputation: 88168
It's a bit tricky, but you can share sets of subplots with a common colorbar.
I've drawn on a few previous anwers that might be worth reading as well:
Matplotlib 2 Subplots, 1 Colorbar
How can I create a standard colorbar for a series of plots in python
And of course, the documentation for matplotlib:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
# Generate some random data
data_top = np.random.random((3,10,10)) * 5
data_bot = np.random.random((3,20,20)) * 10
fig = plt.figure()
grid_top = ImageGrid(fig, 211, nrows_ncols = (1, 3),
cbar_location = "right",
cbar_mode="single",
cbar_pad=.2)
grid_bot = ImageGrid(fig, 212, nrows_ncols = (1, 3),
cbar_location = "right",
cbar_mode="single",
cbar_pad=.2)
for n in xrange(3):
im1 = grid_top[n].imshow(data_top[n],
interpolation='nearest', vmin=0, vmax=5)
im2 = grid_bot[n].imshow(data_bot[n], cmap=plt.get_cmap('bone'),
interpolation='nearest', vmin=0, vmax=10)
grid_top.cbar_axes[0].colorbar(im1)
grid_bot.cbar_axes[0].colorbar(im2)
plt.show()
Upvotes: 4