Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ENH: Add parameter to set line width of legend frame (closes #30095) #30103

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
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
6 changes: 5 additions & 1 deletion 6 lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def get_legend_handles_labels(self, legend_handler_map=None):
return handles, labels

@_docstring.interpd
def legend(self, *args, **kwargs):
def legend(self, *args, framelinewidth=None, **kwargs):
"""
Place a legend on the Axes.

Expand Down Expand Up @@ -330,6 +330,10 @@ def legend(self, *args, **kwargs):
"""
handles, labels, kwargs = mlegend._parse_legend_args([self], *args, **kwargs)
self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)

if framelinewidth is not None:
self.legend_.get_frame().set_linewidth(framelinewidth)

self.legend_._remove_method = self._remove_legend
return self.legend_

Expand Down
6 changes: 6 additions & 0 deletions 6 lib/matplotlib/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@
assert_allclose(leg_bboxes[1].bounds, leg_bboxes[0].bounds)
assert_allclose(leg_bboxes[2].bounds, leg_bboxes[0].bounds)

def test_legend_framelinewidth():

Check failure on line 110 in lib/matplotlib/tests/test_legend.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Expected 2 blank lines, found 1 Raw Output: message:"Expected 2 blank lines, found 1" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/tests/test_legend.py" range:{start:{line:110 column:1} end:{line:110 column:4}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"E302" url:"https://docs.astral.sh/ruff/rules/blank-lines-top-level"} suggestions:{range:{start:{line:109 column:1} end:{line:110 column:1}} text:"\n\n"}
fig, ax = plt.subplots()
ax.plot([0, 1], [0, 1], label="test")
leg = ax.legend(frameon=True, framelinewidth=5.0)
assert leg.get_frame().get_linewidth() == 5.0


def test_legend_auto5():
"""
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.