Skip to content

Implemented Issue #3225. Added a uniform_size parameter to legend. #4247

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
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,10 @@ def legend(self, handles, labels, *args, **kwargs):
*title* : string
the legend title

*uniform_size*: [ *None* | scalar ]
a uniform size of legend markers. If *None*, use original plot
settings

Padding and spacing between various elements use following keywords
parameters. The dimensions of these values are given as a fraction
of the fontsize. Values from rcParams will be used if None.
Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def __init__(self, parent, handles, labels,
bbox_transform=None, # transform for the bbox
frameon=None, # draw frame
handler_map=None,
uniform_size=None, # set legend points to be a uniform size
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also docment in the docstring

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I noticed the keyword arguments for legend is also mentioned in figure.py. I'll add to that part as well.

):
"""
- *parent*: the artist that contains the legend
Expand Down Expand Up @@ -223,6 +224,7 @@ def __init__(self, parent, handles, labels,
title the legend title
bbox_to_anchor the bbox that the legend will be anchored.
bbox_transform the transform for the bbox. transAxes if None.
uniform_size the uniform size of legend marker
================ ====================================================


Expand All @@ -245,6 +247,13 @@ def __init__(self, parent, handles, labels,

Artist.__init__(self)

if uniform_size is not None:
uniform_handler_map = {
PathCollection:
legend_handler.HandlerPathCollection(sizes=[uniform_size]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only line that changes anything right? Couldn't this be done by just updating just this handler?

}
self.update_default_handler_map(uniform_handler_map)

if prop is None:
if fontsize is not None:
self.prop = FontProperties(size=fontsize)
Expand Down