有沒有一種方法來控制網格格式,當做pandas.DataFrame.plot()?pandas:我如何顯示pd.DataFrame.plot()中的x軸上的次要網格線
具體而言,我想展示一個用具有DateTimeIndex的x軸繪製DataFrame的次要網格線。
這是可能的通過DataFrame.plot()?
df = pd.DataFrame.from_csv(csv_file, parse_dates=True, sep=' ')
有沒有一種方法來控制網格格式,當做pandas.DataFrame.plot()?pandas:我如何顯示pd.DataFrame.plot()中的x軸上的次要網格線
具體而言,我想展示一個用具有DateTimeIndex的x軸繪製DataFrame的次要網格線。
這是可能的通過DataFrame.plot()?
df = pd.DataFrame.from_csv(csv_file, parse_dates=True, sep=' ')
這將繪製小號& P500與每週頻率輕微xticks和網格:
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')
DataFrame.plot()
應該從matplotlib返回Axes
對象。
因此,與ax = df.plot(...)
,你可以這樣做:
ax.xaxis.grid(True, which='minor', linestyle='-', linewidth=0.25, ...)
真棒,我沒有意識到plot()返回一個軸對象。所以我猜想一個PNG圖形以scilab模式顯示在IPython筆記本中,因爲筆記本檢測到軸對象的存在? – user2846226
不錯的一個,但我怎麼能做到這一點使用DataFrame,在我的問題給出?我無法找到相當於ts.index.min()的DataFrame - df.idxmin()會返回一系列... – user2846226
@ user2846226對於DataFrame而言'df.index.min()'也應該可以工作,除非它是多索引 –
確實,用戶錯誤 – user2846226