python - 使 matplotlib 导出图形 svg 没有描边

标签 python matplotlib svg

我正在尝试使用 Python 和 matplotlib 生成一个 svg 文件。我使用的代码的更简单版本如下:

import matplotlib.pyplot as plt


plt.figure()
plt.fill([0,1,0.5],[0,0,1],color = "r")
plt.fill([1.5,1,0.5],[1,0,1],color = "b")
plt.show()
plt.savefig("soedgesvg.svg")

到目前为止一切顺利,结果符合预期: enter image description here

但是当我在 Inkscape 中打开它时,我得到了一个没有指定颜色的意外重影边缘。这可以在下图中看到:

enter image description here

有没有办法在导出 svg 之前在 Python 中删除这条边?

编辑

根据我的经验,只有在指定颜色时才会发生这种情况。

Inkscape 0.92.3 和 matplotlib 3.1.1

最佳答案

也可以在调用 plt.fill 时添加 linewidth=0 ,如下所示:

plt.fill([0,1,0.5],[0,0,1],color = "r", linewidth=0)
plt.fill([1.5,1,0.5],[1,0,1],color = "b", linewidth=0)

此答案由 @ImportanceOfBeingErnest 提供在评论中有以下解释:

Because the linewidth is defined in points. When you zoom inside matplotlib, the lines always keep their physical size, e.g. 1/72. of an inch. When you zoom in in Inkscape you zoom into the actual figure, up to the point where maybe your screen only shows 1/72. of an inch and hence the line will be as large as the screen.

关于python - 使 matplotlib 导出图形 svg 没有描边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57381514/

相关文章:

python - 如何根据 sku 从 woocommerce api 获取产品?

python - 禁用 `@tf.function` 装饰器进行调试?

python - 如何检查两级循环中的键?

python - 在 python matplotlib 中的 plot_surface 顶部绘制单个 3D 点

python - 剧情: color all larger than different color

java - 如何通过java代码将VML转换为SVG或VML转换为位图图像?

Python - 从 csv 文件中读取特定列

python - Matplotlib Python : How to add panel button

html - 有没有办法让 svg 多边形阴影具有不透明度?

android - 通过在 Canvas 中绘图使用 Vector Drawable