Skip to content

Commit

Permalink
Update utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
A-CGray authored Nov 16, 2023
1 parent be76687 commit d31aec9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 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
Lines to label, by default all lines in the axes whose labels don't begin with an underscore
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,11 +279,13 @@ 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 = ax.get_lines()
lines = [line for line in ax.get_lines() if line.get_label()[0] != "_"]

if labels is None:
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 d31aec9

Please sign in to comment.