首页 > 解决方案 > Pandas Plot:如何在同一个 pdf 文件中导出数据框和图形?

问题描述

df = 
period                r1           r2            r3      r4
2.0000            -0.102500      -0.105248     -0.0345 -0.1356
3.0000            -0.110000      -0.113534     -0.106 -0.14100
4.0000            -0.105625      -0.114568     -0.091 -0.15100
5.0000            -0.094375      -0.103994     -0.071 -0.16000
6.0000            -0.078125      -0.088134     -0.891 -0.11100
7.0000            -0.059375      -0.064697     -0.211 -0.18000
8.0000            -0.038125      -0.041853     -0.091  0.08313
9.0000            -0.014375      -0.017881     -0.075 -0.17800
10.0000             0.011875       0.007937      0.031 -0.04375
12.0000             0.057187       0.054960     -0.091  0.08313
15.0000             0.123125       0.117267      0.155  0.08313
20.0000             0.203750       0.209123      0.245  0.17375
25.0000             0.255312       0.258802      0.346  0.27875

ax = plt.gca()
ax.set_xlim(0, 50)
ax.xaxis.set_major_locator(MultipleLocator(2))
ax.xaxis.set_minor_locator(AutoMinorLocator(4))

df.plot(kind='line',x='period', y= 'r1', color='red', figsize=(15,10), ax=ax)
df.plot(kind='line',x='period', y= 'r2', color='green', figsize=(15,10), ax=ax)
df.plot(kind='line',x='period', y='r3', color='blue', figsize=(15,10), ax=ax)
df.plot(kind='line',x='period', y='r4', color='blue', figsize=(15,10), ax=ax)

plt.show()
fig = ax.get_figure()
dir = '....pdf'
fig.savefig(dir)

我可以知道如何导出上述数据框并在同一个 pdf 中绘图。我想要第一页的图表和第二页的数据框。怎么做。请问有什么建议吗?

标签: pythonpandasmatplotlib

解决方案


推荐阅读