Matplotlib: How to implement missing grid lines on subplots with different axes limits?
I'm currently working on a multi-panel figure using Matplotlib, and I've encountered an scenario where the grid lines are not showing up in the subplots when the axes limits differ significantly. I'm using Matplotlib version 3.5.1, and here's a simplified version of my code: ```python import matplotlib.pyplot as plt import numpy as np x1 = np.linspace(0, 10, 100) y1 = np.sin(x1) y2 = np.cos(x1) fig, axs = plt.subplots(1, 2, figsize=(12, 5)) axs[0].plot(x1, y1) axs[0].set_xlim(0, 10) axs[0].set_ylim(-1, 1) axs[0].grid(True) axs[1].plot(x1, y2) axs[1].set_xlim(0, 10) axs[1].set_ylim(-0.5, 0.5) axs[1].grid(True) plt.tight_layout() plt.show() ``` Despite calling `grid(True)` on both axes, I only see grid lines on the first subplot. The second subplot doesn't show the grid lines at all. I've tried adjusting the limits and re-enabling the grid, but it still doesn't appear. I suspect it might have something to do with the y-axis limits being close to zero. Any suggestions on how to ensure that grid lines are consistently displayed in both subplots? I've also checked other related questions on StackOverflow but couldn't find a solution to this specific question.