Skip to content
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

Improve default behaviour of label_line_ends #38

Merged
merged 6 commits into from
Nov 16, 2023
Merged
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
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