Doopy
Doopy

Reputation: 706

Matplotlib: fill_between drawing rounded edges in SVG when color is set

I've encountered a strange issue when using matplotlibs fill_between with data that has a tight gap. For example, when I simply want to plot the following data and save it as SVG, it works:

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

But when I set the color to any value, the gap disappears:

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

After zooming in I noticed the edge line is drawn with rounded borders: enter image description here

How can I change the plot color without this gap disappearing? I've tried to set different kwargs like capstyle, joinstyle, antialiased, rasterized,... to all possible values without success.

Upvotes: 0

Views: 348

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339220

You are setting the color of the patch. This would include the edgecolor and the facecolor. However, it seems you only want to have the face colored. Hence use 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

Upvotes: 1

Related Questions