Matplotlib:设置颜色时在SVG中绘制圆角边缘的fill_between

时间:2018-09-15 11:34:15

标签: python matplotlib svg

在将matplotlibs fill_between与差距很小的数据一起使用时,我遇到了一个奇怪的问题。例如,当我只想绘制以下数据并将其保存为SVG时,它就可以工作:

import matplotlib.pyplot as plt

plt.fill_between([0,1e4-1000,1e4,1e4+1000,1e6], [1000,1000,1,1000,1000])
plt.savefig("test.svg")

enter image description here

但是当我将颜色设置为任何值时,间隙消失了:

import matplotlib.pyplot as plt

plt.fill_between([0,1e4-1000,1e4,1e4+1000,1e6], [1000,1000,1,1000,1000], color='tab:red')
plt.savefig("test_colored.svg")

enter image description here

放大后,我注意到边缘线被绘制成圆角边框: enter image description here

如何在不消失此间隙的情况下更改绘图颜色? 我尝试将capstylejoinstyleantialiasedrasterized等不同的kwarg设置为所有可能的值,但均未成功。

1 个答案:

答案 0 :(得分:1)

您正在设置补丁程序的color。这将包括edgecolor和facecolor。但是,看来您只想让脸彩色。因此,请使用facecolor='tab:red'

import matplotlib.pyplot as plt

plt.fill_between([0,1e4-1000,1e4,1e4+1000,1e6], [1000,1000,1,1000,1000], facecolor='tab:red')
plt.savefig("test_colored.svg")
plt.show()

enter image description here