I have a plot and I want to draw some vertical lines covering the whole range of the y-axis, without having to worry about the numerical values of that range. This matplotlib example demonstrates the functionality I'm looking for, and it works fine for me, but a very similar code does not. What am I doing wrong?
from matplotlib import pyplot as plt
import numpy as np
np.random.seed(19680801)
y = np.random.normal(scale=0.01, size=200).cumsum()
fig, ax = plt.subplots(1, 2, figsize=(12, 6))
ax[0].plot(y)
ax[0].vlines([25, 50, 100], [0], [0.1, 0.2, 0.3], color='C1')
ax[1].plot(y)
ax[1].vlines([25, 50, 100], [0], [0.1, 0.2, 0.3], color='C1')
ax[1].vlines([0], 0, 1, color='k', linestyle='dashed',
transform=ax[1].get_xaxis_transform())
Expected: both plots have the same y-limits
Actual result: the plot on the right has the wrong limits
Using matplotlib 3.7.1 on python 3.11.3.