Skip to content

Commit 6e901fa

Browse files
authored
Merge pull request #215 from scottshambaugh/broadcast_xvals
Allow for single value passed in to `xvals`, similar to `yoffsets`
2 parents cff30c0 + 408486a commit 6e901fa

File tree

4 files changed

+89
-62
lines changed

4 files changed

+89
-62
lines changed

Readme.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ lines = ax.get_lines()
5757
l1 = lines[-1]
5858
labelLine(
5959
l1,
60-
0.6,
60+
0.85,
6161
label=r"$Re=${}".format(l1.get_label()),
62-
ha="left",
63-
va="bottom",
6462
align=False,
63+
yoffset=0.01,
64+
ha="right",
6565
backgroundcolor="none",
6666
)
67-
labelLines(lines[:-1], yoffsets=0.01, align=False, backgroundcolor="none")
67+
labelLines(lines[:-1], xvals=0.85, yoffsets=0.01, align=False,
68+
ha="right", backgroundcolor="none")
6869

6970
# labelLines also supports log-scaled x-axes
7071
ax = axes[4]

example.png

640 Bytes
Loading

example/matplotlib_label_lines.ipynb

+82-58
Large diffs are not rendered by default.

labellines/core.py

+2
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ def labelLines(
248248
xvals[order] = old_xvals # type: ignore
249249
else:
250250
xvals = list(always_iterable(xvals)) # force the creation of a copy
251+
if len(xvals) == 1:
252+
xvals = [xvals[0]] * len(all_lines)
251253

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

0 commit comments

Comments
 (0)