2016-08-23 1 views

Antwort

1

Legen Sie für einige Ticks leere Tick-Labels fest.

# based on http://matplotlib.org/examples/ticks_and_spines/ticklabels_demo_rotation.html 
import matplotlib.pyplot as plt 
x = [1, 2, 3, 4] 
y = [1, 4, 9, 6] 
labels = ['Frogs', 'Hogs', '', 'Slogs'] 

plt.plot(x, y, 'ro') 
# You can specify a rotation for the tick labels in degrees or with keywords. 
plt.xticks(x, labels, rotation='vertical') 
# Pad margins so that markers don't get clipped by the axes 
plt.margins(0.2) 
# Tweak spacing to prevent clipping of tick-labels 
plt.subplots_adjust(bottom=0.15) 
plt.show() 

enter image description here

+0

Cool! Fast da! Also, wie soll ich diese Etiketten mit einer großen Anzahl von Daten definieren (wenn meine Etiketten numerisch sind)? Zum Beispiel wenn x = np.arange (0,100,1) und ich möchte, dass meine Labels 10, 20, ... usw. sind? Ich habe lables = np.arange (0,100,10) versucht, aber es hat nicht funktioniert ... Danke – durbachit

+0

Ok, ich dachte mir, wie ich es umgehen kann. Einfach durch eine if-Teilbarkeitsschleife! – durbachit

1

Nur meinen Kommentar auf Serenitys Antwort zu beantworten, ist hier, wie die numerischen Etiketten zu bekommen.

x = range(100) 
labels = [] 
for i in x: 
    if i % 10 == 0: 
     i=i 
    else: 
     i=' ' 
    labels.append(i) 

Und das macht den Job.

Verwandte Themen