Python Matplotlib 透明线图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4320021/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 15:14:38  来源:igfitidea点击:

Matplotlib transparent line plots

pythonmatplotlib

提问by Gus

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 中绘制两个类似的轨迹,我想绘制具有部分透明度的每条线,以便红色(第二个绘制)不会遮挡蓝色。

alt text

替代文字

EDIT: Here's the image with transparent lines.

编辑:这是带有透明线条的图像。

alt text

替代文字

采纳答案by Davoud Taghawi-Nejad

Plain and simple:

干净利落:

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

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

(我知道我没有添加任何新内容,但应该可以看到直接的答案)。

回答by moinudin

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.

这实际上取决于您用于绘制线条的函数,但请尝试查看您使用的 on 是否采用 alpha 值并将其设置为 0.5 之类的值。如果这不起作用,请尝试获取线条对象并直接设置它们的 alpha 值。

回答by Gus

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.

编辑:请在评论中查看乔的回答。