2021-07-18

Show entire minor gridline in matplotlib figure

I would like to show the topmost minor gridline (at 2.25) in its full width without adjusting the limits manually. How can I achieve this?

import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl

t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)

fig, ax = plt.subplots(constrained_layout=True)

ax.yaxis.set_tick_params(which='minor', width=5)
ax.plot(t, s)
ax.yaxis.set_major_locator(mpl.ticker.MultipleLocator(0.50))
ax.yaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.25))
ax.grid(linewidth=5, axis='y', which='both')
ax.set_ylim(0, 2.25)

plt.show()

Screenshot



from Recent Questions - Stack Overflow https://ift.tt/3ew6qnD
https://ift.tt/3kA6TJv

No comments:

Post a Comment