使用透明标记但不透明的边缘进行绘图 [英] Plotting with a transparent marker but non-transparent edge

查看:106
本文介绍了使用透明标记但不透明的边缘进行绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在matplotlib中使用具有固定颜色边的透明标记来绘制图.但是,我似乎无法实现透明填充的标记.

I'm trying to make a plot in matplotlib with transparent markers which have a fixed color edge . However, I can't seem to achieve a marker with transparent fill.

我这里有一个最低限度的工作示例:

I have a minimum working example here:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(10)
y1 = 2*x + 1
y2 = 3*x - 5

plt.plot(x,y1, 'o-', lw=6, ms=14)
plt.plot(x,y2, 'o', ms=14, markerfacecolor=None, alpha=0.5, markeredgecolor='red', markeredgewidth=5)

plt.show()

我尝试了两种在网上找到的技术来实现这一目标: 1)设置alpha参数.然而,这也使标记边缘也透明,这不是期望的效果. 2)设置markerfacecolor = None,尽管这对我的情节没有影响

I tried two techniques I found online to achieve this: 1) Setting alpha parameter. However, this makes the marker edge transparent too, which is not the desired effect. 2) Setting markerfacecolor=None, although this has no effect on my plot

请问有解决办法吗?

推荐答案

在Matplotlib中这很棘手...您必须使用字符串"None"代替值None,然后您可以执行以下操作:

This is tricky in Matplotlib... you have to use a string "None" instead of the value None, then you can just do:

plt.plot(x,y2, 'o', ms=14, markerfacecolor="None",
         markeredgecolor='red', markeredgewidth=5)

这篇关于使用透明标记但不透明的边缘进行绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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