Prevent grid lines from twin axis to be drawn on top of artists from original axis
问题 I have an axis on which I plot some data and I have another twin axis which I use to draw grid lines at specific tick positions (other than the ticks of the original axis): import matplotlib.pyplot as plt import numpy as np f, ax = plt.subplots() ax.set_xlim([0, 1]) ax2 = ax.twiny() ax2.set_xlim([0, 1]) ax2.set_xticks(np.linspace(0, 1, 11)) ax2.xaxis.grid() x = np.linspace(0, 1, 100) ax.plot(x, np.sin(x), label='sin(x)') ax.legend() plt.show() Now this has the undesirable effect that the grid