python - 从pdf中的循环中保存多个图
问题描述
我有大型数据集,我在其中绘制和拟合循环 x(df_time)vs y(df_intensity 中的所有列。我想保存所有通过拟合生成的图,但我似乎无法管理,我只能设法显示它们。
我还在情节下方得到一条线,可能表明问题所在,但我找不到替代方案。有没有一种方法可以轻松实现另存为 pdf 的方式,即每页获得多个图(我正在生成数百个,所以我想我将需要多个页面,所以理想情况下是自动将其保存在 pdf 中并且当页面已满,请转到下一页。非常感谢!
fname must be a PathLike or file handle
我正在使用以下代码:
coefficients=[]
for column in df_intensity:
try:
plt.scatter(df_time01, column)
plt.show()
# starting point for the decay to fit
decay_start = np.argmax(column)
# use only decay points in the fit
guess = [1, 0.001, 0]
popt, pcov = curve_fit(func, df_time01[decay_start:],
column[decay_start:],
p0=guess)
# get the fit curve
#try:
fit = func(df_time01[decay_start:], *popt)
# plot the fit and data
plt.plot(df_time01[decay_start:], fit, label='fit', c='r')
plt.scatter(df_time01, column, label='data')
plt.legend()
plt.show()
print('Fit parameters: {}'.format(popt))
coefficients.append(popt)
plt.savefig(column, dpi=300, transparent=True)
with PdfPages('multipage_pdf.pdf') as pdf:
plt.figure(figsize=(3, 3))
plt.plot
plt.title('Page One')
pdf.savefig() # saves the current figure into a pdf page
plt.close()
except Exception as e:
print(e)
print("Error - curve_fit failed")
continue
解决方案
推荐阅读
- java - Failed to connect to remote VM while trying to configure Remote Debug of java application deployed on tomcat of Windows Server
- database - Many-to-Many Relationships across 4 Tables
- python - Python Datetime 将格式转换为 dd/mm/yyyy HH:MM:SS
- c# - 有没有办法防止子元素继承 XAML 和 C# 中的事件处理程序?
- python - 使用 cx_oracle 连接 Oracle 12c 时出错
- mysql - (2027,“格式错误的数据包”)
- visual-studio - Visualizer 扩展程序崩溃并且无法恢复库存(Visual Studio 2019)
- linux - 通过 shell 脚本将 /etc/fstab 文件中的选项 noexec 替换为 exec
- php - 根据产品 SKU 向 WooCommerce 订单项目添加随机字符串
- c++ - 在 Visual C++ 中使用 IntelliJ Reshaper 时如何将 printf(...) 检查提示应用于自定义函数?