Skip to content

Setting alpha on legend handle changes patch color #11702

@bpteague

Description

@bpteague

Bug report

Bug summary

I occasionally want the alpha value of the patch in a histogram's legend to be different than the alpha value used to plot the legend. However, when I call set_alpha on a legend handle, the color of the patch in the legend changes.

Code for reproduction

import matplotlib.pyplot as plt

plt.hist([1, 2, 3], alpha = 0.25, label = 'data', color = 'red')
legend = plt.legend()
for lh in legend.legendHandles:
    lh.set_alpha(1.0)

Actual outcome

image

Work-around

I can get the result I desire if I call set_edgecolor() and set_facecolor():

plt.hist([1, 2, 3], alpha = 0.25, label = 'data', color = 'red')
legend = plt.legend()
for lh in legend.legendHandles:
    lh.set_facecolor(lh.get_facecolor())
    lh.set_edgecolor(lh.get_edgecolor())
    lh.set_alpha(1.0)

Expected outcome

image

Matplotlib version

  • Matplotlib v2.2.2
  • Installed from Anaconda (default channel)
  • Backend: module://ipykernel.pylab.backend_inline
  • Jupyter version: 5.5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy