有两个子图
我正在尝试在子图中创建一个沿x轴的日期条形图。 以下是代码
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()
这会引发错误。
TypeError: float() argument must be a string or a number
如果我们绘制条形图和折线图
是否有问题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 :(得分:0)
基本上,我只需要很少的修改就可以复制并粘贴你的代码,并且使用python 3.4对我有用。 xlabels需要一些改进。
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()