我想在
Python中创建两个子图(使用Anaconda 2.7),但我编写的代码生成两个图,两者都没有显示太多.
这是代码:
import pandas as pd
import pandas.io.data as web
import matplotlib.pyplot as plt
from matplotlib import style
style.use('ggplot')
import datetime
start = datetime.datetime(2000, 10, 23)
end = datetime.datetime(2016, 10, 23)
df = web.DataReader("BAC", "yahoo", start, end)
df['100MA'] = pd.rolling_mean(df['Adj Close'], 100, min_periods=1)
df['STD'] = pd.rolling_std(df['Close'], 25, min_periods=1)
print(df.tail())
ax1 = plt.subplot(2, 1, 1)
df[['Adj Close', '100MA']].plot()
ax2 = plt.subplot(2, 1, 2, sharex=ax1)
df['STD'].plot()
plt.show()
提前致谢!