Q:

How to stop xlim updating when subplots share x-axis

If I have
import matplotlib.pyplot as plt

plt.plot([0,1], [0,1])
plt.plot([0,2], [0,1], scalex=False)

plotting the second line does not update the axes xlim:

However, if I create subplots with a shared x-axis, the scalex kwarg appears to have no effect:
fig, ax_arr = plt.subplots(2, 1, sharex=True)
for ax in ax_arr.flat:
    ax.plot([0,1], [0,1])
    ax.plot([0,2], [0,1], scalex=False)

Is there another kwarg or setting somewhere that can be used to stop a plotted line affecting the axes xlim in this example?

A:

scalex affects the autoscaling in the moment the plot is created. It will not be stored to take effect in further calls to autoscale.
An option is to turn autoscaling off in general for all but the first axes. 
import matplotlib.pyplot as plt

fig, ax_arr = plt.subplots(2, 1, sharex=True)

ax_arr[1].set_autoscalex_on(False)

for ax in ax_arr.flat:
    ax.plot([0,1], [0,1])
    ax.plot([0,2], [0,1], scalex=False)

plt.show()

