小编Jas*_*son的帖子

如何使Matplotlib散点图作为一组透明?

我正在使用Matplotlib制作一些散点图(python 3.4.0,matplotlib 1.4.3,在Linux Mint 17上运行).很容易为每个点单独设置alpha透明度; 有没有办法将它们设置为一个组,以便来自同一组的两个重叠点不会改变颜色?

示例代码:

import matplotlib.pyplot as plt
import numpy as np

def points(n=100):
    x = np.random.uniform(size=n)
    y = np.random.uniform(size=n)
    return x, y
x1, y1 = points()
x2, y2 = points()
fig = plt.figure(figsize=(4,4))
ax = fig.add_subplot(111, title="Test scatter")
ax.scatter(x1, y1, s=100, color="blue", alpha=0.5)
ax.scatter(x2, y2, s=100, color="red", alpha=0.5)
fig.savefig("test_scatter.png")
Run Code Online (Sandbox Code Playgroud)

结果输出:

在此输入图像描述

但我想要更像这样的东西:

在此输入图像描述

我可以通过保存为SVG并在Inkscape中手动分组,然后设置透明度来解决,但我真的更喜欢我可以编码的东西.有什么建议?

python transparency matplotlib scatter-plot

13
推荐指数
4
解决办法
2万
查看次数

标签 统计

matplotlib ×1

python ×1

scatter-plot ×1

transparency ×1