我想使用Gridspec配置子图大小,如本问题中所述. Python/Matplotlib - 更改子图的相对大小
怎么做,如果我想使用Pandas Dataframe的情节功能?有可能吗?
你可以这样做.
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)
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
968 次 |
| 最近记录: |