for l in a.lines:
    x, y = l.get_data()
start, stop = np.searchsorted(x, xlim)
yc = y[max(start - 1, 0):stop + 1]
ylim = min(ylim[0], np.nanmin(yc)), max(ylim[1], np.nanmax(yc))
a.set_xlim(xlim, emit=False)
corners = (xlim[0], ylim[0]), (xlim[1], ylim[1])
a.dataLim.update_from_data_xy(corners, ignore=True, updatex=False)
a.autoscale(enable=True, axis='y')
a.xlim = xlim
for ax in fig.axes:
    ax.callbacks.connect('xlim_changed', on_xlim_changed)
matplotlib linked x axes with autoscaled y axes on zoom