0

I would like to configure the subplots size using Gridspec as explained in this question. Python/Matplotlib - Change the relative size of a subplot

How do this, If i want to use Pandas Dataframe's plot funtion? Is it possible at all?

Community
  • 1
  • 1
vumaasha
  • 2,765
  • 4
  • 27
  • 41
  • 2
    You need to be more specific. You can use `df.plot` on any Axes object by passing in to the plot method, eg, `df.plot(..., ax=ax1)` – Paul H Jun 21 '15 at 20:02

2 Answers2

8

You can do it this way.

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

Jianxun Li
  • 24,004
  • 10
  • 58
  • 76
1

I don't think you can use gridspec with pandas plot. pandas plot module is a wrapper around the matplotlib pyplot and does not necessarily implements all the functionality.

If you inspect the pandas source on github and do a search on gridspec you will notice that plot offers no options to configure gridspec

https://github.com/pydata/pandas

nitin
  • 7,234
  • 11
  • 39
  • 53