Matplotlib transparent line plots


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

Asked By: Gus



It really depends on what functions you’re using to plot the lines, but try see if the on you’re using takes an alpha value and set it to something like 0.5. If that doesn’t work, try get the line objects and set their alpha values directly.

Answered By: moinudin

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:

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

Answered By: Gus

Plain and simple:

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

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

Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.