Matplotlib transparent line plots


Question

I am plotting two similar trajectories in matplotlib and I'd like to plot each of the lines with partial transparency so that the red (plotted second) doesn't obscure the blue.

alt text

EDIT: Here's the image with transparent lines.

alt text

1
108
8/14/2019 7:44:33 PM

Accepted Answer

Plain and simple:

plt.plot(x, y, 'r-', alpha=0.7)

(I know I add nothing new, but the straightforward answer should be visible).

196
5/15/2015 2:39:39 PM

After I plotted all the lines, I was able to set the transparency of all of them as follows:

for l in fig_field.gca().lines:
    l.set_alpha(.7)

EDIT: please see Joe's answer in the comments.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon