2017-12-18 13 views
1

Meine aktuelle Grafik zeigt die gesamte Palette von Daten korrekt.Python Probleme Einstellung X-Achse Datenrahmen in Matplotlib

Ich habe Probleme beim Einstellen der X-Achse auf meinem Graphen. Mein Code ist folgende:

prices['Timestamp'] = pd.to_datetime(prices['Timestamp'], format='%Y-%m-%d %H:%M:%S') 
prices['Timestamp'] = pd.DatetimeIndex(prices['Timestamp']) 
prices.index = pd.to_datetime(prices['Timestamp'], format='%Y-%m-%d %H:%M:%S') 


prices['Close'].plot() 

plt.set_xlim([datetime.date(2017, 12, 17), datetime.date(2017, 12, 18)]) 


plt.legend() 
plt.show() 

Das gibt mir den Fehler

Blockquote AttributeError: module 'matplotlib.pyplot' has no attribute 'set_xlim'

ich wirklich meinen Graph will den Zeitstempel zeigen, von 2017.12.17 22.00.00 bis neueste Zeit zu sein .

Probe der Daten wie folgt aussieht:

print(prices['Close'] 

2017-12-18 07:13:00 3.030000e-06 
2017-12-18 07:14:00 3.020000e-06 
2017-12-18 07:15:00 3.030000e-06 
2017-12-18 07:16:00 3.040000e-06 

Dank

Antwort

1

Es scheint, Sie brauchen:

#set column to datetime 
prices['Timestamp'] = pd.to_datetime(prices['Timestamp'], format='%Y-%m-%d %H:%M:%S') 
#set index from column 
prices = prices.set_index('Timestamp') 
#plot column, return matplotlib AxesSubplot object 
ax = prices['Close'].plot() 
#set xlim 
ax.set_xlim([datetime.date(2017, 12, 17), datetime.date(2017, 12, 18)]) 

plt.show() 
+0

ich immer noch das gesamte Spektrum der Daten erhalten. auch ich will nur vom 17.12.2017 22:00:00 bis spätestes mal (nicht nur Termine?). –

+0

Schwierige Frage, was ist mit ax.set_xlim ([datetime.date (2017, 12, 17, 22, 0, 0), df.index.max()]) '? – jezrael

Verwandte Themen