做pandas.DataFrame.plot()时有没有办法控制网格格式?
具体来说,我想显示用于绘制带有x轴且具有DateTimeIndex的DataFrame的次网格线。
是否可以通过DataFrame.plot()?
df = pd.DataFrame.from_csv(csv_file, parse_dates=True, sep=' ')
最佳答案
这将以每周一次的频率绘制带有少量xticks和网格的S&p500:
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' )
关于python - Pandas :如何在pd.DataFrame.plot()的x轴上显示次要网格线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20616754/