Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 306
Gus Avatar asked Dec 01 '10 00:12

Gus


People also ask

How do you make a line invisible in Python?

Make lines, i.e., line1 and line2, using plot() method. To hide the lines, use line. remove() method.

How do you make a bar graph transparent in Matplotlib?

To set transparency for bars in a Bar Plot using Matplotlib PyPlot API, call matplotlib. pyplot. bar() function, and pass required alpha value to alpha parameter of bar() function. Of course, there are other named parameters, but for simplicity, only alpha parameter is given along with required x and height .

How do I change the alpha level in Python?

You can update the alpha value of an existing Line2D , using the set_alpha method. The idea would be to plot the line once and then update the alpha in the loop.

Which parameter should you use to change a plot's transparency?

Inmatplotlib, the plots have a parameter, alpha= to change transparency.


3 Answers

Plain and simple:

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

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

like image 99
Davoud Taghawi-Nejad Avatar answered Oct 02 '22 19:10

Davoud Taghawi-Nejad


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.

like image 44
Gus Avatar answered Oct 02 '22 18:10

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.

like image 35
moinudin Avatar answered Oct 02 '22 17:10

moinudin