简体   繁体   English

将重叠图添加到 pdf 多页

[英]Add overlapping plots to a pdf multipage

I want to add overlapping plots to one subplot of a pdf page with the data: x1 , x2 , y1 , y2 etc. So far this is my current state but it is not working clearly yet to display the subplots in the pdf:我想将重叠图添加到带有数据的 pdf 页面的一个子图中: x1x2y1y2等。到目前为止,这是我当前的状态,但还没有清楚地显示 pdf 中的子图:

import numpy as np
from matplotlib.backends.backend_pdf import PdfPages

mp = PdfPages('multipage.pdf')

plt.grid()
plt.scatter(x1,y1)
plt.step([0,0],[-5,5], linewidth = 3,color ='orange')
plt.step([50,50],[45,55], linewidth = 3,color ='orange')
plt.step([100,100],[95,105], linewidth = 3,color ='orange')
plt.xlabel('x')
plt.ylabel('y')

fig = plt.figure()
ax1 = fig.add_subplot(211)

plt.show()

plt.grid()
plt.scatter(x2,y2)
plt.step([0,0],[-5,5], linewidth = 3,color ='orange')
plt.step([50,50],[45,55], linewidth = 3,color ='orange')
plt.step([100,100],[95,105], linewidth = 3,color ='orange')
plt.xlabel('x')
plt.ylabel('y')

fig = plt.figure()
ax2=fig.add_subplot(212)

plt.show()

mp.savefig(fig)

mp.close()

I'm not sure if this is what you're looking for, but perhaps it will offer some help.我不确定这是否是您正在寻找的,但也许它会提供一些帮助。 This is an adaptation of the example referenced in your comment to use PdfPages :这是对您评论中引用的示例的改编,以使用PdfPages


from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)

fig, axs = plt.subplots(2, 2)
axs[0, 0].plot(x, y)
axs[0, 1].plot(x, y, 'tab:orange')
axs[1, 0].plot(x, -y, 'tab:green')
axs[1, 1].plot(x, -y, 'tab:red')

mp = PdfPages('multipage.pdf')

mp.savefig(fig)
mp.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM