Registry / data / matplotlib-label-lines

matplotlib-label-lines

JSON →
library0.8.1pypypi✓ verified 84d ago

Label lines in matplotlib by adding text annotations near specified line segments. Version 0.8.1, supports Python >=3.9. Release cadence is low, no major updates in recent years.

pip install matplotlib-label-lines
INSTALL
IMPORT
SIG · MATPLOTLIB-LABEL-L
M
matplotlib-label-lines
datapythonv0.8.1
Install
7.7s avg
Import
2705ms
Disk
182MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.8.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 2.744s · 179MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 7.7s · import 2.666s · 171MB
182MB installed
● package 182MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

labelLines
from labellines import labelLines
import labelLines
Module name is 'labellines' (no spacing), function is labelLines.
labelLine
from labellines import labelLine
from labellines import label_lines
Function is camelCase, not snake_case.

Basic example: plot three lines and label them with automatic positioning.

import matplotlib.pyplot as plt import numpy as np from labellines import labelLines x = np.linspace(0, 1, 100) fig, ax = plt.subplots() for i in range(1, 4): ax.plot(x, x**i, label=f'$x^{i}$') labelLines(ax.get_lines()) plt.show()
Debug
Known issues
gotchalabelLines uses the line's label for text; if no label is set, it silently skips the line.
fix
Ensure every line you want labeled has a label string set via the 'label' parameter in plot.
affects: all
gotchalabelLines positions labels based on the data range; if x or y data is not sorted, label placement may be unexpected.
fix
Sort your data before plotting or use labelLine for manual control.
affects: all
deprecatedIn matplotlib 3.7+, get_lines() returns an immutable sequence; modifying the returned list is no longer possible.
fix
No change needed for labeling, but do not attempt to mutate ax.get_lines() directly.
affects: >=0.8.1
gotchaThe 'xvals' parameter expects x-coordinate values in data space; if you pass fractional axes coordinates, labels will be misplaced.
fix
Use data coordinates for xvals, or convert using ax.transData.transform().
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'labellines'
Attempted import with wrong name (e.g., 'matplotlib_label_lines' or 'labellines' misspelled).
fix
Install via pip and use: from labellines import labelLines
ImportError: cannot import name 'labelLines' from 'labellines'
Older version of the library (before 0.6.0) used a different function name or the module is not installed correctly.
fix
Upgrade to latest version: pip install --upgrade matplotlib-label-lines
KeyError: 'label' when calling labelLines
One or more lines in the collection do not have a label set (label is empty or None).
fix
Set label for each line: plt.plot(x, y, label='my line') or pass lines with labels only.
Upgrade
Version history
0.8.1latest on PyPI · released Apr 25, 2025
Audit
Dependencies
matplotlibrequiredRequired for plotting
numpyrequiredUsed internally for coordinate handling
Agent activity
4 hits · last 30 days
node
4
Resources
matplotlib-label-lines — pip install matplotlib-label-lines · libregistry