So I have followed the approach from this thread:
How can I plot the same figure standalone and in a subplot in Matplotlib?
And it actually works quite well, as seen in his example. However, one issue is that I have inset_axes
plots in my plots. So when it zooms, all the inset plots remains, and actually overlaps the enlarged plot.
I am however not sure how to remove them, and maybe even also zoom in on the inset plot that are together with the subplot being clicked.
So from the thread I have just used this class for the zoom approach:
class ZoomingSubplots(object):
def __init__(self, *args, **kwargs):
"""All parameters passed on to 'subplots`."""
self.fig, self.axes = plt.subplots(*args, **kwargs)
self._zoomed = False
self.fig.canvas.mpl_connect('button_press_event', self.on_click)
self.fig.subplots_adjust(hspace=0.3)
def zoom(self, selected_ax):
for ax in self.axes.flat:
ax.set_visible(False)
self._original_size = selected_ax.get_position()
selected_ax.set_position([0.125, 0.1, 0.775, 0.8])
selected_ax.set_visible(True)
self._zoomed = True
def unzoom(self, selected_ax):
selected_ax.set_position(self._original_size)
for ax in self.axes.flat:
ax.set_visible(True)
self._zoomed = False
def on_click(self, event):
if event.inaxes is None:
return
if self._zoomed:
self.unzoom(event.inaxes)
else:
self.zoom(event.inaxes)
self.fig.canvas.draw()
And then when I plot I use this:
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
__name__ = '__main__':
subplots = ZoomingSubplots(2, 2)
for ax in subplots.axes.flat:
ax.plot(x, y)
axins = inset_axes(ax, width=1.3, height=0.9, loc=2)
axins.plot(x2, y2)
plt.show()
But as stated, with this the inset plot for all subplots will remain in their position and overlap with the enlarged plot. How can I change this, so that they don't intervene, and maybe even the inset_plot for the subplot remains and is also enlarged ?