I’m using matplotlib’s mpl_toolkits.axes_grid1.ImageGrid
to generate two grids, each size (3,3):
JavaScript
x
11
11
1
import matplotlib.pyplot as plt
2
from mpl_toolkits.axes_grid1 import ImageGrid
3
from graspologic.plot import binary_heatmap, adjplot
4
5
fig = plt.figure(figsize=(16,8))
6
7
grid1 = ImageGrid(fig, 121, (3, 3), axes_pad=.05, share_all=True)
8
grid2 = ImageGrid(fig, 122, (3, 3), axes_pad=.05, share_all=True)
9
10
plt.tight_layout(w_pad=3)
11
I’m trying to figure out how to add a title to each ImageGrid, so that there would be two titles, one for the left 3×3 grid, and one for the right one.
It seems like this should be pretty straightforward, but I haven’t been able to figure it out so far. Anybody familiar with this and have any good ideas? Thanks!
Advertisement
Answer
There doesn’t appear to be a built in way to set the title of an ImageGrid.
However, you could get the list of axes objects that are used to make the ImageGrid using grid1.axes_all
, then set the title of the top middle one. It’s a bit of a workaround, but works in this case.
JavaScript
1
12
12
1
from mpl_toolkits.axes_grid1 import ImageGrid
2
3
fig = plt.figure(figsize=(16,8))
4
5
grid1 = ImageGrid(fig, 121, (3, 3), axes_pad=.05, share_all=True)
6
grid2 = ImageGrid(fig, 122, (3, 3), axes_pad=.05, share_all=True)
7
8
plt.tight_layout(w_pad=3)
9
10
grid1.axes_all[1].set_title("Left hand title")
11
grid2.axes_all[1].set_title("Right hand title")
12