You can use list comprehension.
[ax.set_xlabel("x label") for ax in [ax1,ax2]]
You can also set labels when creating a subtask, which simplifies the complete code from the question to one line:
fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1, subplot_kw=dict(xlabel="xlabel") )
source
share