将多个绘图保存在一个 PDF 文件中

编程入门 行业动态 更新时间:2024-10-28 05:26:57
本文介绍了将多个绘图保存在一个 PDF 文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 def plotGraph(X,Y): fignum = random.randint(0,sys.maxint) plt.figure(fignum) ### Plotting arrangements ### return fignum

主模块

import matplotlib.pyplot as plt ### tempDLStats, tempDLlabels are the argument plot1 = plotGraph(tempDLstats, tempDLlabels) plot2 = plotGraph(tempDLstats_1, tempDLlabels_1) plot3 = plotGraph(tempDLstats_2, tempDLlabels_2) plt.show()

我想将所有图形 plot1、plot2、plot3 保存到一个 PDF 文件中.有什么方法可以实现吗?我无法在主模块中包含 plotGraph 函数.

I want to save all the graphs plot1, plot2, plot3 to a single PDF file. Is there any way to achieve it? I can't include the plotGraph function in the main module.

有一个名为 pyplot.savefig 的函数,但它似乎只适用于单个图形.还有其他方法可以实现吗?

There's a function named pyplot.savefig but that seems to work only with a single figure. Is there any other way to accomplish it?

推荐答案

没关系有办法去做.

def plotGraph(X,Y): fignum = random.randint(0,sys.maxint) fig = plt.figure(fignum) ### Plotting arrangements ### return fig

------绘图模块------

------ plotting module ------

----- 主模块 ----

----- mainModule ----

import matplotlib.pyplot as plt ### tempDLStats, tempDLlabels are the argument plot1 = plotGraph(tempDLstats, tempDLlabels) plot2 = plotGraph(tempDLstats_1, tempDLlabels_1) plot3 = plotGraph(tempDLstats_2, tempDLlabels_2) plt.show() plot1.savefig('plot1.png') plot2.savefig('plot2.png') plot3.savefig('plot3.png')

----- mainModule -----

----- mainModule -----

更多推荐

将多个绘图保存在一个 PDF 文件中

本文发布于:2023-08-05 11:25:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1305218.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   在一   文件   PDF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!