How to make Matplotlib scatterplots transparent as a group?

后端 未结 4 1492
栀梦
栀梦 2021-02-07 03:19

I\'m making some scatterplots using Matplotlib (python 3.4.0, matplotlib 1.4.3, running on Linux Mint 17). It\'s easy enough to set alpha transparency for each point individuall

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-07 03:49

    Interesting question, I think any use of transparency will result in the stacking effect you want to avoid. You could manually set a transparency type colour to get closer to the results you want,

    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")
    alpha = 0.5
    ax.scatter(x1, y1, s=100, lw = 0, color=[1., alpha, alpha])
    ax.scatter(x2, y2, s=100, lw = 0, color=[alpha, alpha, 1.])
    plt.show()
    

    The overlap between the different colours are not included in this way but you get,

    enter image description here

提交回复
热议问题