开发者

Matplotlib transparent line plots

开发者 https://www.devze.com 2023-01-28 11:37 出处:网络
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.

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.

Matplotlib transparent line plots

EDIT: Here's the image with transparent lines.

开发者_如何学Go

Matplotlib transparent line plots


Plain and simple:

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

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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号