FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

MNT: Minor cleanup of label formatting in PathCollection.legend_elements by timhoffm · Pull Request #31412 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
15 changes: 10 additions & 5 deletions lib/matplotlib/collections.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,15 @@ def legend_elements(self, prop="colors", num="auto",
"alpha": self.get_alpha(),
**kwargs}

for val, lab in zip(values, label_values):
# Pre-format all labels
# TODO: check whether we can switch to
# formatted_labels = fmt.format_ticks(label_values)
# There are subtle differences for some formatters as that passes the
# indices to __call__ as well.
fmt.set_locs(label_values)
formatted_labels = [fmt(lab) for lab in label_values]

for val, formatted in zip(values, formatted_labels):
if prop == "colors":
color = self.cmap(self.norm(val))
elif prop == "sizes":
Expand All @@ -1281,10 +1289,7 @@ def legend_elements(self, prop="colors", num="auto",
h = mlines.Line2D([0], [0], ls="", color=color, ms=size,
marker=self.get_paths()[0], **kw)
handles.append(h)
if hasattr(fmt, "set_locs"):
fmt.set_locs(label_values)
l = fmt(lab)
labels.append(l)
labels.append(formatted)

return handles, labels

Expand Down
Loading

Back | FazBrowse Home | New Git URL