The following is the explanation of the preceding code:
- figmain, axmain = plt.subplots() defines the figure and axes for the main window, and figzoom, axzoom = plt.subplots() defines the figure and axes for the zoom window.
- axmain.set(xlim=(-5, 5), ylim=(-75, 175), autoscale_on=False, title='Click to zoom') sets properties such as the x and y axis limits, whether autoscale is on or off, and the title for the main axes, and axzoom.set(xlim=(-2, 2), ylim=(-8, 8), autoscale_on=False, title='Zoom window') defines the same properties for the zoom axis.
- x = np.arange(-5, 5, 0.1) and y = x ** 3 are the data for plotting a non-linear curve.
- axmain.plot(x, y, 'g-d') plots the non-linear curve on the main axis, and axzoom.plot(x, y, ...