Skip to content

Patch edgecolor of a legend item does not follow look of figure #7375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jorisvandenbossche opened this issue Nov 1, 2016 · 2 comments
Closed
Milestone

Comments

@jorisvandenbossche
Copy link

It's not about the edgecolor of the legend box, but of the legend items (if they are a patch). In the following example, the clear border around the patches in the legend is a bit surprising to me, and contrasts the look of the figure itself.

Example code:

fig, ax = plt.subplots()
ax.hist(np.random.randn(1000), alpha=0.5, label='group 1')
ax.hist(np.random.randn(1000) + 2, alpha=0.5, label='group 2')
ax.legend()

index

As a notebook: http://nbviewer.jupyter.org/gist/jorisvandenbossche/68b2831ea2b87c76d944e93edc134d59

This issue now surfaces because the default changed to no border for patches, and as such for the histogram in this example (before 2.0, this would not be an issue with the default look). And it becomes more apparent due to the use of a lower alpha in this specific example.

Not sure if this is still the case with master, but I tested with matplotlib 2.0.0b4, on Python 3.5 / Ubuntu (installed from conda-forge)

@anntzer
Copy link
Contributor

anntzer commented Nov 2, 2016

The culprit is https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/patches.py#L295

self._edgecolor = colors.to_rgba(color, self._alpha)

i.e. the edgecolor of the legend patch inherits the alpha value set by default.

Fundamentally, this is again a consequence of the design choice of having alpha as a separate attribute, when it should really be part of the color spec (of course this doesn't prevent having helper functions to access and modify the alpha value).

As a stopgap measure, I think we can fix to_rgba (and friends) to have a force_alpha=True kwarg, and use force_alpha=False here in the meaning of "use the alpha value from the color itself if it specifies one". But I'd say that ultimately, removing internal use of a separate alpha attribute (which can be done without changing the public API) is the way to go.

@NelleV
Copy link
Member

NelleV commented Nov 22, 2016

closed in #7497

@NelleV NelleV closed this as completed Nov 22, 2016
@QuLogic QuLogic added this to the 2.0 (style change major release) milestone Nov 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants