Das Gitter verschwindet (ok), aber kleine Häkchen (an der Stelle der Haupthäkchen) bleiben. Wie entferne ich sie?
John Vinyard
Der plt.tick_params Methode ist sehr nützlich für solche Sachen. Dieser Code schaltet Haupt- und Nebenstriche aus und entfernt die Beschriftungen von der x-Achse.
Beachten Sie, dass es auch gibt ax.tick_params für matplotlib.axes.Axes Objekte.
from matplotlib import pyplot as plt
plt.plot(range(10))
plt.tick_params(
axis="x", # changes apply to the x-axis
which="both", # both major and minor ticks are affected
bottom=False, # ticks along the bottom edge are off
top=False, # ticks along the top edge are off
labelbottom=False) # labels along the bottom edge are off
plt.show()
plt.savefig('plot')
plt.clf()
Nicht genau das, wonach das OP gefragt hat, aber eine einfache Möglichkeit, alle Achsenlinien, Häkchen und Beschriftungen zu deaktivieren, besteht darin, einfach Folgendes aufzurufen:
plt.axis('off')
Haschmus
Alternativ können Sie eine leere Tick-Position übergeben und als kennzeichnen
# for matplotlib.pyplot
# ---------------------
plt.xticks([], [])
# for axis object
# ---------------
# from Anakhand May 5 at 13:08
# for major ticks
ax.set_xticks([])
# for minor ticks
ax.set_xticks([], minor=True)