1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Matplotlib stacked histogram problem with alpha

Discussão em 'Python' iniciado por Stack, Março 29, 2025.

  1. Stack

    Stack Membro Participativo

    I want to plot two data sets in a histogram using stacked = True but setting the alpha parameter is not working correctly. The colors of the histograms just get lighter instead of transparent. Have a look for yourself:

    import matplotlib.pyplot as plt
    import numpy as np

    np.random.seed(123)

    mu_x = 200
    sigma_x = 25
    x = np.random.normal(mu_x, sigma_x, size=100)

    mu_x = 150
    sigma_x = 25
    y = np.random.normal(mu_x, sigma_x, size=100)

    plt.hist([x,y], stacked=True, alpha=0.5, bins=10)

    plt.show()


    I tried defining colors for the histograms like plt.hist([x,y], color = [(0, 0, 1, 0.3),(1, 0, 0, 0.3) stacked=True, bins=10) but the problem stays the same.

    Does anybody know how to solve this?

    [​IMG]

    Continue reading...

Compartilhe esta Página