Home > front end >  Matplotlib fill_beween: remove color leak
Matplotlib fill_beween: remove color leak

Time:08-31

This code

import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
x = np.linspace(0, 4)
y = x ** 2
y2 = x ** 2.1
ax.fill_between(x, y, y2, alpha=0.25, color='red')
fig.save_fig('plot.pdf')

gives the following, when zooming in:

enter image description here

I don't want the boundaries (which are visible as lines) to appear.

This problem only occurs when I save the figure. Also, if I remove color='red', the problem disappears as well.

CodePudding user response:

Adding linewidth=0 removes the lines.

Full code:

import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
x = np.linspace(0, 4)
y = x ** 2
y2 = x ** 2.1
ax.fill_between(x, y, y2, alpha=0.25, color='red', linewidth=0)
fig.save_fig('plot.pdf')
  • Related