图例标记透明度 - Matplotlit

时间:2014-07-18 14:38:20

标签: python matplotlib plot opacity legend

我有一个带有rgba点的情节,当我向他们展示传奇时,我得到了带有alpha值的标记传奇。如何以完全不透明的方式显示它们?

简化,这是我绘制点并显示图例的方式:

x = np.arange(10)
y = np.arange(10)

alphas = np.linspace(0.1, 1, 10)
rgba_colors = np.zeros((10,4))
rgba_colors[:,0] = 1.0
rgba_colors[:, 3] = alphas

plt.scatter(x, y, color=rgba_colors, marker='x', facecolors='none', linewidth=2, label='Min Points')

plt.legend(loc='center left', scatterpoints = 1)

这就是我得到的:

enter image description here

可以看出,图例标记有点透明。如何以完全不透明的方式显示它们?

我尝试了this方法,这就是我得到的(根本没有 x 标记):

enter image description here

当我更改color=='white参数时,我在标记上划了一条线。

enter image description here

提前谢谢。

1 个答案:

答案 0 :(得分:2)

我可以使用这段代码解决它:

marker_min = plt.Line2D((0, 0), (0, 0), markeredgecolor=(0.5, 0.0, 0.0), markerfacecolor='none', linestyle='', marker='x', markeredgewidth=2, markersize=5)
marker_max = plt.Line2D((0, 0), (0, 0), markeredgecolor=(0.0, 0.5, 0.0), markerfacecolor='none', linestyle='', marker='o', markeredgewidth=2, markersize=5)
plt.legend([marker_min, marker_max], ['Min Points', 'Max Points'], numpoints=1, loc='center left', bbox_to_anchor=(1, 0.5))

enter image description here

不知道这是否是最佳解决方案。

相关问题