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

Allow for single value passed in to xvals, similar to yoffsets #215

Merged
merged 2 commits into from
Apr 1, 2025
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
9 changes: 5 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ lines = ax.get_lines()
l1 = lines[-1]
labelLine(
l1,
0.6,
0.85,
label=r"$Re=${}".format(l1.get_label()),
ha="left",
va="bottom",
align=False,
yoffset=0.01,
ha="right",
backgroundcolor="none",
)
labelLines(lines[:-1], yoffsets=0.01, align=False, backgroundcolor="none")
labelLines(lines[:-1], xvals=0.85, yoffsets=0.01, align=False,
ha="right", backgroundcolor="none")

# labelLines also supports log-scaled x-axes
ax = axes[4]
Expand Down
Binary file modified example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
140 changes: 82 additions & 58 deletions example/matplotlib_label_lines.ipynb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions labellines/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ def labelLines(
xvals[order] = old_xvals # type: ignore
else:
xvals = list(always_iterable(xvals)) # force the creation of a copy
if len(xvals) == 1:
xvals = [xvals[0]] * len(all_lines)

lab_lines, labels = [], []
# Take only the lines which have labels other than the default ones
Expand Down