我有一个像这样的csv文件:
trade_dt IC pValue
2011/2/28 0.005834749 0.794163818
2011/3/31 -0.016185318 0.465113735
2011/4/29 0.0535994 0.014731813
2011/5/31 -0.023620263 0.278485983
2011/6/30 -0.000771114 0.971613898
2011/7/29 -0.063454359 0.003181087
2011/8/31 0.13892734 6.60E-11
2011/9/30 0.003624149 0.864731069
2011/10/31 0.055471084 0.008852478
首先,我使用pd.read_csv
阅读此文件。其次,我使用pd.to_datetime()
转换trade_dt。
当我使用ax.xaxis.set_major_formatter(mdate.DateFormatter('%Y%m%d'))
进行绘制时,它会显示,例如2011-2-28 00:00
我有两个问题:
2011-2-28 00:00
这是我的代码。请忽略一些与此问题无关的代码和缩进
def analysis_factor_ic(_df_ic):
corrData = _df_ic.copy()
corrData['monthly_IC'] = corrData.IC.rolling(window=5, center=False).mean()
corrData['xtick'] = range(len(corrData))
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
fig = plt.figure(figsize=(16, 6))
ax = fig.add_subplot(111)
sigPos = corrData[(corrData.IC > 0) & (corrData.pValue < 0.05)]
sigNeg = corrData[(corrData.IC < 0) & (corrData.pValue < 0.05)]
nonSig = corrData[~(corrData.pValue < 0.05)]
ax.bar(sigPos.xtick, sigPos.IC, align='center', color='r', label=u'显著为正')
ax.bar(nonSig.xtick, nonSig.IC, align='center', color='grey', label=u'不显著')
ax.bar(sigNeg.xtick, sigNeg.IC, align='center', color='g', label=u'显著为负')
plt.legend(loc='best')
ax.xaxis.set_major_formatter(mdate.DateFormatter('%Y%m%d'))
plt.xticks(corrData.xtick[1:-1:3], corrData.index[1:-1:3])
plt.xlim(-1, len(corrData))
fig.autofmt_xdate(rotation=-90, ha='center')
plt.grid(axis='y')
plt.title(u'因子Rank IC值')
plt.show()
df_ic = pd.read_csv('dfic.csv')
df_ic['trade_dt'] = pd.to_datetime(df_ic['trade_dt'], format='%Y-%m-%d')
df_ic.set_index(df_ic['trade_dt'], inplace=True)
analysis_factor_ic(df_ic)