【问题标题】:df.plot adding to itself instead of in separate figuredf.plot 添加到自身而不是单独的图中
【发布时间】:2016-05-18 20:51:51
【问题描述】:

下面的代码应该给我单独的图表,每个图表都有一行数据,但由于某种原因,第一个图显示了“GrowthVsValue”线,然后第二个图再次显示了“GrowthVsValue”线并添加了“LargeVsSmall”线。但我希望他们在单独的数字中独立存在。我需要添加/做些什么来完成这项工作??

from matplotlib.backends.backend_pdf import PdfPages
pp = PdfPages('Relative Strength.pdf')

Output = pd.DataFrame({

'GrowthVsValueDIFF': 1 + (df_ch['IVV'] - df_ch['IVE']),
'LargeVsSmallDIFF':  1 + (df_ch['IVV'] - df_ch['IJR']),

}, index = df_ch.index)


Output['GrowthVsValue'] = 100
Output.loc[1:, 'GrowthVsValue'] = Output.GrowthVsValueDIFF[1:].cumprod() * 100
Output.GrowthVsValue.plot.line(legend=None)
Output.GrowthVsValue_L = plt.title('Growth v. Value RS')
plt.savefig(pp, format='pdf')

Output['LargeVsSmall'] = 100
Output.loc[1:, 'LargeVsSmall'] = Output.LargeVsSmallDIFF[1:].cumprod() * 100
Output.LargeVsSmall.plot.line(legend=None)
Output.LargeVsSmall_L = plt.title('Large v. Small RS')
plt.savefig(pp, format='pdf')

pp.close()

【问题讨论】:

    标签: python pandas matplotlib dataframe


    【解决方案1】:

    在第一个 plt.savefig() 之后使用 plt.close()

    【讨论】:

    • 它总是很简单哈!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多