Matplotlib-如何使标记面颜色透明而不使线透明 [英] Matplotlib - How to make the marker face color transparent without making the line transparent

查看:1282
本文介绍了Matplotlib-如何使标记面颜色透明而不使线透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何在matplotlib中设置线条的透明度.例如,以下代码使直线和标记透明.

I know how to set the transparency of a line in matplotlib. For example, the following code makes the line and the markers transparent.

import numpy as np
import matplotlib.pyplot as plt

vec = np.random.uniform(0, 10, 50)
f = plt.figure(1)
ax = f.add_subplot(111)
ax.plot(vec, color='#999999', marker='s', alpha=0.5)

我希望线条的alpha = 1.0,而标记的面部颜色是半透明的(alpha = 0.5).可以在matplotlib中完成吗?

I want line's alpha=1.0, and marker's face color to be semi-transparent (alpha=0.5). Can this be done in matplotlib?

谢谢.

推荐答案

有关使用一行完成此操作的正确方法,请参见下面的@Pelson答案.

您可以通过将两个独立的Line2D对象粘在一起以一种怪诞的方式来实现此目的.

See @Pelson's answer below for the correct way to do this with one line.

You can do this in a hacky way by sticky taping together two independent Line2D objects.

th = np.linspace(0, 2 * np.pi, 64)
y = np.sin(th)
ax = plt.gca()

lin, = ax.plot(th, y, lw=5)
mark, = ax.plot(th, y, marker='o', alpha=.5, ms=10)

ax.legend([(lin, mark)], ['merged'])
plt.draw()

请参阅此处以获取解释

这篇关于Matplotlib-如何使标记面颜色透明而不使线透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆