从以下数据帧和系列生成 pdf 时,pandas 会生成两个空白图形并将它们插入到我的 .pdf 文件中。图 1 和图 3 都是空白的,而图 2 和图 4 正在打印到 .pdf 文件。我曾希望将以下所有三个数字(图 1、图 2 和图 3)写入 .pdf 文件。
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
from pandas.tools.plotting import bootstrap_plot
from pandas.tools.plotting import scatter_matrix
from pandas import *
range_days = 10
ydate = "2014-09-09"
wdate = "2014-08-31"
c_data = [1,2,3,4,3,2,1,3,4,5]
p_data = [1,2,3,4,3,2,1,3,4,5]
d_data = [1,2,3,4,3,2,1,3,4,5]
d = {"C":Series(c_data, index=date_range(wdate, periods=range_days)),"P": Series(p_data, index=date_range(wdate, periods=range_days)),"D":Series(d_data, index=date_range(wdate, periods=range_days))}
d2 = {"C":d["C"], "P":d["P"]}
ts2 = DataFrame(d2, index=date_range(wdate, periods=range_days))
ts = DataFrame(d, index=date_range(wdate, periods=range_days))
pdf_name = "Metrics_" + str(wdate) + "_to_" + str(ydate)+ ".pdf"
pdf = PdfPages(pdf_name)
#P & C over time
fig1 = plt.figure()
ts2.plot(secondary_y=["P"])
pdf.savefig(fig1)
#Density Plot of C
fig2 = plt.figure()
d["C"].plot(kind="kde")
pdf.savefig(fig2)
#scatter matrix on the data_frame
fig3 = plt.figure()
scatter_matrix(ts, alpha=0.2, figsize=(6, 6), diagonal='kde')
pdf.savefig(fig3)
pdf.close()