I noticed that two adjacent areas overlap, so in the middle appear an annoying line. I tried "capstyle = 'butt'" which I used to avoid overlap between lines, but here it doesn't do the job.
here's a minimal example:
import matplotlib.pylab as plt
ax = plt.subplot(111)
ax.axvspan(0, 0.5, color = 'red', alpha = 0.13, capstyle = 'butt')
ax.axvspan(0.5, 1, color = 'blue', alpha = 0.13, capstyle = 'butt')
plt.show()
The problem you have is not due to line caps, since axvspan draws a polygon. The problem is that this polygon, by default, has a border with a given linewidth (one pixel, I suppose).
So, to get just the areas without that "border", set the linewidth (lw
) to zero:
import matplotlib.pylab as plt
ax = plt.subplot(111)
ax.axvspan(0, 0.5, color = 'red', alpha = 0.13, lw=0)
ax.axvspan(0.5, 1, color = 'blue', alpha = 0.13, lw=0)
plt.show()
Instead of color
, use facecolor
inside axvspan
. The solution by @heltonbiker works great, it gets rid of the width of the border. But, at least in the matplotlib version I'm using, 2.0.0, using just facecolor
doesn't draw the border.
import matplotlib.pylab as plt
fig,ax = plt.subplots()
ax.axvspan(0, 0.5, facecolor = 'red', alpha = 0.13)
ax.axvspan(0.5, 1, facecolor = 'blue', alpha = 0.13)
plt.show()
Using only facecolor
will no draw the border:
Using color
will fill the rectangle and will draw a border:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With