Reputation: 447
Is there a way to control grid format when doing pandas.DataFrame.plot()?
Specifically i would like to show the minor gridlines for plotting a DataFrame with a x-axis which has a DateTimeIndex.
Is this possible through the DataFrame.plot()?
df = pd.DataFrame.from_csv(csv_file, parse_dates=True, sep=' ')
Upvotes: 28
Views: 59412
Reputation: 4672
Maybe this feature didn't exist last year, but in version 0.19.2 you can do:
df.plot(grid=True)
See the doc.
Upvotes: 57
Reputation: 77951
this will plot S&p500 with minor xticks and grids at weekly frequency:
import pandas.io.data as web
ts = web.DataReader("^GSPC", "yahoo", start=dt.date( 2013, 6, 1 ))[ 'Adj Close' ]
ax = ts.plot()
xtick = pd.date_range( start=ts.index.min( ), end=ts.index.max( ), freq='W' )
ax.set_xticks( xtick, minor=True )
ax.grid('on', which='minor', axis='x' )
ax.grid('off', which='major', axis='x' )
Upvotes: 29
Reputation: 68146
DataFrame.plot()
should return an Axes
object from matplotlib.
So with ax = df.plot(...)
, you can do:
ax.xaxis.grid(True, which='minor', linestyle='-', linewidth=0.25, ...)
Upvotes: 7