【发布时间】:2021-09-09 09:14:12
【问题描述】:
前面的讨论 [1] 帮助我们将 matplotlib 图导出为 .emf 文件。然而,奇怪的错误是输出文件有节点填充黑色背景,如下所示。
如何获得与 .svg 完全相同的 .emf?
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])
【问题讨论】:
标签: python matplotlib svg inkscape