-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add legend.linewidth parameter to control legend box edge linewidth #30780
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
Changes from all commits
8f42926
d92308c
6d4de61
1d7ed10
c931dc6
8541748
2dee159
6f24f53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| ``legend.linewidth`` rcParam and parameter | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| A new rcParam ``legend.linewidth`` has been added to control the line width of | ||
| the legend's box edges. When set to ``None`` (the default), it inherits the | ||
| value from ``patch.linewidth``. This allows for independent control of the | ||
| legend frame line width without affecting other elements. | ||
|
|
||
| The `.Legend` constructor also accepts a new *linewidth* parameter to set the | ||
| legend frame line width directly, overriding the rcParam value. | ||
|
|
||
| .. plot:: | ||
| :include-source: true | ||
| :alt: A line plot with a legend showing a thick border around the legend box. | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the |
||
| import matplotlib.pyplot as plt | ||
|
|
||
| fig, ax = plt.subplots() | ||
| ax.plot([1, 2, 3], label='data') | ||
| ax.legend(linewidth=2.0) # Thick legend box edge | ||
| plt.show() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -562,6 +562,7 @@ | |
| #legend.framealpha: 0.8 # legend patch transparency | ||
| #legend.facecolor: inherit # inherit from axes.facecolor; or color spec | ||
| #legend.edgecolor: 0.8 # background patch boundary color | ||
| #legend.linewidth: None # line width of the legend frame, None means inherit from patch.linewidth | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems we have a mixture already in that we sometimes use "inherit" and sometimes None. We should do an analysis of the cases and decide which one to use in the future.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the point about consistency. I followed the edgecolor pattern which uses "inherit". Happy to adjust based on the team's preferred convention.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, we are inconsistent already. rcParams using inherit:
rcParams using None:
rcParams using auto
Summary
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for clarifying. Is there anything needed from my side to move this PR forward being merged? |
||
| #legend.fancybox: True # if True, use a rounded box for the | ||
| # legend background, else a rectangle | ||
| #legend.shadow: False # if True, give background a shadow effect | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.