Skip to content
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

Change the size of legend markers... #12417

Open
jklymak opened this issue Oct 6, 2018 · 8 comments
Open

Change the size of legend markers... #12417

jklymak opened this issue Oct 6, 2018 · 8 comments

Comments

@jklymak
Copy link
Member

jklymak commented Oct 6, 2018

Closed a PR that did this, which was probably over engineered. But the main idea is probably still useful.

#11127 is a bit different, it would create many legend entries for a single scatterplot. The idea here was to unify the size of different scatter plot's handles. Many options are shown in the stackoverflow question "setting a fixed size for points in legend". The easiest is just:

legend = plt.legend()
for legobj in legend.legendHandles:
    legobj.set_sizes([64])

My faviourite, which I just added to that thread as well would be to use the update function of the Handler.

def update(handle, orig):
    handle.update_from(orig)
    handle.set_sizes([64])

plt.legend(handler_map={PathCollection : HandlerPathCollection(update_func=update)})

Originally posted by @ImportanceOfBeingErnest in #4257 (comment)

@h-vetinari
Copy link

Saved my day. This really should work out of the box. Why do the legend markers change size at all...? I get the point where the only legend info is the size of the marker, but often it's colors/categories etc. that should be in the legend first and foremost.

@ImportanceOfBeingErnest
Copy link
Member

Why do the legend markers change size at all...?

Usually you want a legend to show the marker in the same size as it appears in the plot. For a scatter with different sizes, there is no general way to determine which of the used sizes would be the best to show in the legend - this requires some user input.

But of course feel free to make a suggestion here. Given two scatter plots

sc1 = ax.scatter(..., s=[5,10,15])
sc2 = ax.scatter(..., s=[32,64,128])

which "automatic" size would you expect to see in a legend?

@h-vetinari
Copy link

which "automatic" size would you expect to see in a legend?

Just the normal fontsize of the legend? Or, maybe more accurately, a constant size so that the markers in the legend do not overlap -- something visually pleasing w.r.t. to the already fixed linespacing size (IOW, maybe slightly larger than the fontsize, but smaller than fontsize+linespacing).

@ImportanceOfBeingErnest
Copy link
Member

Actually, I don't know why #4247 wasn't pursued further. It looks much more straight forward than #4257.
I think @h-vetinari 's suggestion could be easily incoorporated as an uniform_size="auto" parameter (although it might not be possible to easily update the legend once fontsize or linespacing change after legend creation).

@bf
Copy link

bf commented May 7, 2020

It'd be great if this is further pursued by someone who is able to implement it. It is one of the most important things that's missing in my day-to-day pyplot use.

@github-actions
Copy link

github-actions bot commented Jun 7, 2023

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jun 7, 2023
@github-actions github-actions bot added the status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. label Jul 10, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2023
@h-vetinari
Copy link

Pity that this got closed, I missed the ping a year ago... 😑

@rcomer
Copy link
Member

rcomer commented Jul 10, 2023

@h-vetinari we are happy to re-open these bot-closed issues if someone is still interested in them.

@rcomer rcomer reopened this Jul 10, 2023
@rcomer rcomer removed status: inactive Marked by the “Stale” Github Action status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. labels Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants