Skip to content

Commit

Permalink
Improve default behaviour of label_line_ends (#38)
Browse files Browse the repository at this point in the history
* Update utils.py

* Alter logic

* Typo

* Update utils.py

* Update utils.py

* Bump minor version
  • Loading branch information
A-CGray authored Nov 16, 2023
1 parent be76687 commit 2c7bc26
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion niceplots/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.4.1"
__version__ = "2.5.0"

from .utils import *
from .parula import *
6 changes: 6 additions & 0 deletions niceplots/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +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
if lines is None:
lines = ax.get_lines()

if labels is None:
# If we're not given labels, use the lines' label attributes, 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 2c7bc26

Please sign in to comment.