'Stacking Subplots in Matplotlib

i would like to stack 2 subplots so that one of them is in front of the other one. In addition to that i would like to set the size of the subplot in the back a little bit bigger than the subplot in the front in order to see the edges. Here is an example how it should look.

enter image description here

For both subplots i need to use ax = Subplot(fig,111) and fig.add_subplot(ax) cause i want to implement a gridhelper in the subplots.

Is it possible to change the size of ax2 without changing ax1 so that ax2 in the background is slightly bigger than ax1 ?



Solution 1:[1]

This might get you on the right track, although I am not sure how it influences your grid helper requirement:

import numpy as np
from matplotlib import pyplot as plt

x, y = np.linspace(-5, 5, 1024), np.linspace(-5, 5, 1024)

fig = plt.figure()
ax = fig.add_axes((0,0,1,1))  # lower_x, lower_y, width, height
ax.plot(x,y)
ax = fig.add_axes((0.2,0.2,.6,.6))
ax.plot(x,y)

source: here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Fred Shone