I'm fairly new to Python and matplotlib. I want to plot something and on the right hand plot a detail of the main plot. But I don't want to duplicate the plot explicitly, given the complexity of the actual plot
MWE
import numpy as np
import matplotlib.pyplot as plt
x=np.arange(0,10,0.01)
y=np.sin(x)
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.plot(x,y)
# I WANT TO AVOID THIS LINE
ax2.plot(x,y)
# AND USE SOMETHING LIKE ax2=ax1
ax2.set_xlim([0.5,0.7])
ax2.set_ylim(np.sin(ax2.get_xlim()))
plt.show();
Thanks
ax1andax2.