2017-04-27 20 views
-1

Ich habe ein Diagramm, das die Noten über eine Woche hat ich einen einfachen Inkrementierer der x-AchseMatplotlib Wie wird die X-Achse den Wochentagen angepasst?

percent = [] 
count = 0 
time = [] 
for x, y in zip(counts100, counts): 
    percent.append(float(x/y)) 
    time.append(count) 
    count += 1 


plt.xlabel('weekday') 
plt.ylabel('% score over 100') 
plt.plot(time, percent) 
plt.gcf().autofmt_xdate() 
plt.show() 

Diese Daten plotten bin mit percent of scores over 100 by hour

in der Minute Plots richtig angezeigt wird, jedoch x die Achse nur liest die Zahlen.

Wie kann ich dies in Wochentage umwandeln? Dank

EDIT: fand ich diese Antwort here und ich versuche, es zu meinem Problem zu passen und es fast funktioniert, aber ich bekomme immer wieder seltsame Fehler

File "/usr/local/lib/python3.5/dist-packages/matplotlib/dates.py", line 401, in num2date 
return _from_ordinalf(x, tz) 
File "/usr/local/lib/python3.5/dist-packages/matplotlib/dates.py", line 254, in _from_ordinalf 
    dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC) 
ValueError: ordinal must be >= 1 

Antwort

0

fand ich die Lösung here. Bei der Bearbeitung meiner Fragen ändere ich nicht den Wert, der entlang der X-Achse aufgetragen werden soll.

percent = [] 
count = 0 
time = [] 
for x, y, z in zip(counts100, counts, hour): 
    percent.append(float(x/y)) 
    time.append(count) 
    count += 1 
    print("the percent is : {:.4f} for hour {}".format(float(x/y), z)) 



times = pd.date_range('2017-10-06 00:00', periods=count, freq='1H', tz = 'UTC') 

fig, ax = plt.subplots(1) 
fig.autofmt_xdate() 

plt.xlabel('weekday') 
plt.ylabel('% score over 100') 
plt.plot(times, percent) 
xfmt = mdates.DateFormatter('%d %H:%M') 
ax.xaxis.set_major_formatter(xfmt) 

plt.show() 

enter image description here

Verwandte Themen