Pandas: How to display minor grid lines on x-axis in pd.DataFrame.plot()
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, ...)
Maybe this feature didn't exist last year, but in version 0.19.2 you can do:
df.plot(grid=True)
See the doc.
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' )