问题:Matplotlib透明线图

我在matplotlib中绘制了两个相似的轨迹,我想以部分透明的方式绘制每条线,以使红色(绘制的第二个)不会遮盖蓝色。

替代文字

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

替代文字

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


回答 0

干净利落:

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

(我知道我没有添加任何新内容,但是简单的答案应该可见)。

Plain and simple:

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

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


回答 1

绘制完所有线条后,可以如下设置所有线条的透明度:

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

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

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.


回答 2

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

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.


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。