0

我目前正在写一篇科学论文,并且正在使用 matplotlib 生成大部分数据。我有一个使用生成文件设置的管道,每当我更新数据时,它都会重新生成我的所有图。我的问题是这些图形由多个面板组成,其中一些面板应该包含我使用 Adob​​e Illustrator 创建的矢量插图。更新原始数据时,如何自动将图表与插图结合起来?我可以将矢量插图保存为光栅格式,然后使用 matplotlib 的imshow函数显示它们,但我希望输出是矢量以确保最佳的打印质量。

4

2 回答 2

0

经过更广泛的谷歌搜索后,我在 matplotlib 邮件列表中找到了这条旧消息

该线程建议使用 python 库PyX,这对我来说效果很好。

我可以将 illustrator 图和 matplotlib 图保存为 .eps 文件,然后将它们组合在一起,如下所示:

import pyx
c = pyx.canvas.canvas()
c.insert(pyx.epsfile.epsfile(0, 0, "1.eps", align="tl"))
c.insert(pyx.epsfile.epsfile(0,0,"2.eps", align="tr"))
c.writeEPSfile("combined.eps")
于 2014-11-21T10:00:40.587 回答
0

我在 svgutils 文档中找到了这个示例,该文档概述了如何将 matplotlib 生成的 SVG 组合成一个图。

这是该页面的示例:

import svgutils.transform as sg
import sys 

#create new SVG figure
fig = sg.SVGFigure("16cm", "6.5cm")

# load matpotlib-generated figures
fig1 = sg.fromfile('sigmoid_fit.svg')
fig2 = sg.fromfile('anscombe.svg')

# get the plot objects
plot1 = fig1.getroot()
plot2 = fig2.getroot()
plot2.moveto(280, 0, scale=0.5)

# add text labels
txt1 = sg.TextElement(25,20, "A", size=12, weight="bold")
txt2 = sg.TextElement(305,20, "B", size=12, weight="bold")

# append plots and labels to figure
fig.append([plot1, plot2])
fig.append([txt1, txt2])

# save generated SVG files
fig.save("fig_final.svg")
于 2020-07-17T16:29:35.707 回答