Plot grid lines but hide axes

Asked by At

Seems like a simple request but haven't had any luck so far. I thought it would be as simple as

import matplotlib.pyplot as plt

fig = plt.plot([1,2], [1,2])
plt.grid(True)
plt.axis('off')

but that will get rid of the grid as well.

To be clear, I do not want the labels, ticks or thick axis lines, just the grid.

1 Answers

1
Quang Hoang On Best Solutions

Try:

fig, ax = plt.subplots(1,1)
ax.plot([1,2], [1,2])
plt.grid(True)
ax.set_xticklabels([])
ax.set_yticklabels([])
ax.set_frame_on(False)
ax.tick_params(tick1On=False)
plt.show()