前面讨论的 [1]帮助我们将matplotlib图导出为.emf文件。但是,奇怪的错误是,输出文件中的节点填充了黑色背景,如下所示。
如何才能获得与.emf完全相同的.svg?
import matplotlib.pyplot as plt
import subprocess, os
# Graph with 4 nodes - its coordinates
x = [0, 5, 5, 0]
y = [0, 0, 5, 5]
fig, ax = plt.subplots()
# Plot the vertices
for i in range(len(x)):
ax.plot(x[i], y[i], 'ro',
markersize = 12,
fillstyle = 'none',
label = 'A')
# Plot the edges
plt.plot(x,y)
# Legend
handles, labels = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels, handles))
plt.legend(by_label.values(), by_label.keys())
# File export
inkscape_path = "C://Program Files//Inkscape//bin//inkscape.exe"
out_file = "C:/Users/banbar/Desktop/out1.emf"
path, filename = os.path.split(out_file)
filename, extension = os.path.splitext(filename)
svg_filepath = os.path.join(path, filename+'.svg')
emf_filepath = os.path.join(path, filename+'.emf')
fig.savefig(svg_filepath, format='svg')
subprocess.call([inkscape_path, svg_filepath, '--export-filename', emf_filepath])
发布于 2021-06-27 15:38:24
这只是答案的一半,也就是SVG的一半:
当您在Inkscape中选择其中一个方格时,您可能会注意到它在填充指示器所在的左下角显示“填充未设置”。
这是因为matplotlib完全排除了fill属性。SVG中的有效值是“none”,或者是不透明的填充颜色= 0。
我在这里找到了一个关于如何确定填充颜色的链接:https://matplotlib.org/2.1.1/api/_as_gen/matplotlib.pyplot.plot.html
你应该能从那里找出剩下的希望。
发布于 2022-08-04 19:20:24
我有同样的问题,简单的解决办法:
pdf2svg)
)。
问候斯特凡
https://stackoverflow.com/questions/68140087
复制相似问题