2016-04-23 13 views
0

Es zwei subplot sindPlot Balkendiagramm mit Liniendiagramm plot_date und Bar-Funktion

  1. Linechart mit Datum (kein Problem)
  2. Balkendiagramm mit Datum (Ausgabe)

ich versuche Erstellen eines Balkendiagramms mit Datum entlang der X-Achse im Teildiagramm Unten ist der Code

 days = pd.to_datetime(df['indx'].astype(str), format='%Y%m%d') 
    RSI_14 = df['RSI_14'] 
    ATR_14 = df['ATR_14'] 
    fig5 = plt.figure(figsize=(14,9), dpi=200) 
    ax1 = fig5.add_subplot(211) 
    ax2 = fig5.add_subplot(212) 
    ax1.plot_date(x=days, y=RSI_14,fmt="r-",label="ROC_7") 
    ax2.bar(days,ATR_14,width=1) 
    ax2.xaxis_date() 
    pp.savefig() 

Dies führt den Fehler.

TypeError: float() argument must be a string or a number 

Gibt es ein Problem, wenn wir Plot Balkendiagramm mit Liniendiagramm

indx ATR_14 RSI_14 
20141015 0.01737336 99.48281325 
20141016 0.017723579 99.48281325 
20141017 0.020027102 99.53091876 
20141020 0.024023488 99.67180924 
20141021 0.02415369 99.72027954 
20141022 0.026266531 99.76100661 
20141023 0.026764327 85.41188977 
+0

Bei welcher Linie haben Sie den Typeerror? Ich würde ATR_14 überprüfen, um zu sehen, dass es das ist, was Sie denken, dass es sein sollte. – Hun

+0

@Hun Datei "graph_of_every_stock.py", Zeile 90, in Ich habe ATR_14 Problem, das Sie erwähnen, nicht verstanden – nnnnmmm

Antwort

0

Grundsätzlich ich kopieren und einfügen Code mit sehr wenig Änderung, und es funktionierte für mich mit Python 3.4. xlabels müssen verbessert werden.

import pandas as pd 
import matplotlib.pyplot as plt 

df = pd.read_csv('data', delimiter='\s+') 
days = pd.to_datetime(df['indx'].astype(str), format='%Y%m%d') 
RSI_14 = df['RSI_14'] 
ATR_14 = df['ATR_14'] 

fig5 = plt.figure() 
ax1 = fig5.add_subplot(211) 
ax2 = fig5.add_subplot(212) 
ax1.plot_date(x=days, y=RSI_14,fmt="ro-",label="ROC_7") 
ax2.bar(days,ATR_14,width=1) 
ax2.xaxis_date() 
plt.show() 

enter image description here

Verwandte Themen