How to add two color panels to the same section in pyplot (matplotlib)?

I would like to build one subplot, for example:

Title 1
Fig1    Fig2    Fig3 

With a common color panel for these 3 shapes (1,2,3).

Title2
Fig4    Fig5    Fig6

With a common color bar for these 3 shapes (4,5,6).

I did not find a way to add two different color panels in the same figure as above.

+1
source share
1 answer

It's a little tricky, but you can share sets of subheadings with a common color.

enter image description here

I drew a few previous announcements, which may also be worth reading:

Matplotlib 2 subtitles, 1 color bar

How to create a standard color bar for a series of graphs 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()
+4

Source: https://habr.com/ru/post/1623809/


All Articles