0
xValues1 = np.linspace(-5, 5, 5000)
xValues2 = np.linspace(-5, 5, 5000)

yValues1 = -xValues1**2 + 10
yValues2 = -xValues2**2 + 18

plt.ylim(0,20)

plt.plot(xValues1, yValues1, color='green', linewidth=5, alpha=0.5)
plt.plot(xValues2, yValues2, color='cyan', linewidth=5, alpha=0.5)


plt.fill_between(xValues1, yValues1, color='green', alpha=0.5)
plt.fill_between(xValues2, yValues2, color='cyan', alpha=0.5)

Produces this plot where the colors of the line and fill are different.

How can I remedy this?

Community
  • 1
  • 1
  • Do you want to have the lines exactly the same colors as the fill color? If so, why are you drawing the lines at all? Wouldn't you get exactly the desired result with just the fill colors? – Diziet Asahi Jul 18 '18 at 11:42
  • Because sometimes the plot area is very very thin, and plotting just a fill is too small to see. – observereffect Jul 19 '18 at 10:38

1 Answers1

0

It is due to the linewith. Try for both plt.plot functions:

linewidth=0
Ersel Er
  • 731
  • 6
  • 22
  • But I wish to have the linewidth set quite thick. I need it thick as sometimes what I am plotting is too thin to see the fill. – observereffect Jul 18 '18 at 08:02
  • Then, when you have case with a _thin_ filling area you should consider to set the `linewidth` different than 0 by using `if.. else..` code blocks. – Ersel Er Jul 18 '18 at 08:09
  • Unfortunately I need the plot area to be consistent (for a scientific paper). So I would much prefer a way to keep their colors the same if possible. I will experiment with some if-else. – observereffect Jul 18 '18 at 08:16
  • Another idea is that if you have distant volumes/data points you may consider adding another scale to right hand side of the graph and plot the thin/small values with the second scale color. [This](https://stackoverflow.com/questions/9103166/multiple-axis-in-matplotlib-with-different-scales) may help – Ersel Er Jul 18 '18 at 08:20