2015-06-21 26 views

回答

1

我不认为你可以使用gridspec与熊猫的情节。 pandas plot module是matplotlib pyplot的包装,并不一定实现所有功能。

如果检查GitHub上的熊猫源和做gridspec你会发现,阴谋搜索没有提供任何选项来配置gridspec

https://github.com/pydata/pandas

3

你可以这样来做。

import pandas as pd 
import pandas.io.data as web 
import matplotlib.pyplot as plt 

aapl = web.DataReader('AAPL', 'yahoo', '2014-01-01', '2015-05-31') 
# 3 x 1 grid, position at (1st row, 1st col), take two rows 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan=2) 
# plot something on this ax1 
aapl['Adj Close'].plot(style='r-', ax=ax1) 
# plot moving average again on this ax1 
pd.ewma(aapl['Adj Close'], span=20).plot(style='k--', ax=ax1) 
# get the other ax 
ax2 = plt.subplot2grid((3, 1), (2, 0), rowspan=1) 
ax2.bar(aapl.index, aapl.Volume) 

enter image description here

相关问题