I make insets inside particular AXES of a subplot using AX.inset_axes()
. But how do I setup a subplot inside an inset?
Say I have:
FIG = plt.figure()
AXES = plt.gca()
INSET = AXES.inset_axes()
How do I now turn the inset into a subplot with an accessible FIG1 & AXES1 ?
There is only one figure per figure. I’m not clear what you are trying to do - did you want the inset axes split into multiple subplots? Or are you just trying to plot in the inset_axes
? In which case just do inset.plot
or inset.pcolormesh
or whatever plotting you were planning to do there. The state-based pyplot
plt.plot
functions won’t work on the inset, so please use the object=oriented method of accessing the plotting methods (https://matplotlib.org/tutorials/introductory/lifecycle.html)
Standard object based API plots work on the INSET object as @jklymak says. It’s an axes, afterall.
Minimal working example code:
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.inset_locator import inset_axes
fig, ax = plt.subplots(1,1)
inset_ax = inset_axes(ax, width="25%", height="25%", loc=3)
ax.plot([3,2,1], [1,2,3])
inset_ax.plot([1,2,3], [1,2,3])
plt.show()
Yes! That is what I want. I have a main plot, and an inset with sub-plots.
Not trivially. inset axes is meant to respond to changes in the figure particularly it can be in data space. If you just want to put 4 subplots somewhere on the figure, you probably don’t need inset_axes.
How would you suggest I do that? I thought the only way to get one figure inside another is via the inset mechanism.