python画的图怎么保存_Python Matplotlib 画多个图保存到一个pdf文件中

pylab_examples example code: multipage_pdf.py

"""

This is a demo of creating a pdf file with several pages,

as well as adding metadata and annotations to pdf files.

"""

import datetime

import numpy as np

from matplotlib.backends.backend_pdf import PdfPages

import matplotlib.pyplot as plt

# Create the PdfPages object to which we will save the pages:

# The with statement makes sure that the PdfPages object is closed properly at

# the end of the block, even if an Exception occurs.

with PdfPages('multipage_pdf.pdf') as pdf:

plt.figure(figsize=(3, 3))

plt.plot(range(7), [3, 1, 4, 1, 5, 9, 2], 'r-o')

plt.title('Page One')

pdf.savefig() # saves the current figure into a pdf page

plt.close()

plt.rc('text', usetex=True)

plt.figure(figsize=(8, 6))

x = np.arange(0, 5, 0.1)

plt.plot(x, np.sin(x), 'b-')

plt.title('Page Two')

pdf.attach_note("plot of sin(x)") # you can add a pdf note to

# attach metadata to a page

pdf.savefig()

plt.close()

plt.rc('text', usetex=False)

fig = plt.figure(figsize=(4, 5))

plt.plot(x, x*x, 'ko')

plt.title('Page Three')

pdf.savefig(fig) # or you can pass a Figure object to pdf.savefig

plt.close()

# We can also set the file's metadata via the PdfPages object:

d = pdf.infodict()

d['Title'] = 'Multipage PDF Example'

d['Author'] = u'Jouni K. Sepp\xe4nen'

d['Subject'] = 'How to create a multipage pdf file and set its metadata'

d['Keywords'] = 'PdfPages multipage keywords author title subject'

d['CreationDate'] = datetime.datetime(2009, 11, 13)

d['ModDate'] = datetime.datetime.today()

————————————————

版权声明:本文为CSDN博主「狒狒森」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/cym0359/article/details/87930641

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值