Skip to content

Commit

Permalink
Alter logic
Browse files Browse the repository at this point in the history
  • Loading branch information
A-CGray committed Nov 16, 2023
1 parent d31aec9 commit 061a245
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions niceplots/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def label_line_ends(ax, lines=None, labels=None, colors=None, x_offset_pts=6, y_
ax : Matplotlib axes
axes to label the lines of
lines : iterable of matplotlib line objects, optional
Lines to label, by default all lines in the axes whose labels don't begin with an underscore
Lines to label, by default all lines in the axes
labels : list of strings, optional
Labels for each line, by default uses each line's label attribute
colors : single or list of colors, optional
Expand All @@ -279,13 +279,17 @@ def label_line_ends(ax, lines=None, labels=None, colors=None, x_offset_pts=6, y_
list of matplotlib annotation objects
The annotations created
"""

# By default label all lines in the plot whose labels don't begin with an underscore
if lines is None:
lines = [line for line in ax.get_lines() if line.get_label()[0] != "_"]
lines = [line for line in ax.get_lines()]

if labels is None:
# If we're not given labels, use the liness label attribute, but ignore any lines that are still using the
# matplotlib default label which starts with an underscore
lines = [line for line in lines if not line.get_label().startswith("_")]
labels = [line.get_label() for line in lines]

numLines = len(lines)
if len(labels) != numLines:
raise ValueError(f"Number of labels ({len(labels)}) doesn't match number of lines ({numLines})")
Expand Down

0 comments on commit 061a245

Please sign in to comment.