{"id":24016,"library":"matplotlib-label-lines","title":"matplotlib-label-lines","description":"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.","status":"active","version":"0.8.1","language":"python","source_language":"en","source_url":"https://github.com/cphyc/matplotlib-label-lines","tags":["matplotlib","annotation","label","plot","visualization"],"install":[{"cmd":"pip install matplotlib-label-lines","lang":"bash","label":"Install via pip"}],"dependencies":[{"reason":"Required for plotting","package":"matplotlib","optional":false},{"reason":"Used internally for coordinate handling","package":"numpy","optional":false}],"imports":[{"note":"Module name is 'labellines' (no spacing), function is labelLines.","wrong":"import labelLines","symbol":"labelLines","correct":"from labellines import labelLines"},{"note":"Function is camelCase, not snake_case.","wrong":"from labellines import label_lines","symbol":"labelLine","correct":"from labellines import labelLine"}],"quickstart":{"code":"import matplotlib.pyplot as plt\nimport numpy as np\nfrom labellines import labelLines\n\nx = np.linspace(0, 1, 100)\nfig, ax = plt.subplots()\nfor i in range(1, 4):\n    ax.plot(x, x**i, label=f'$x^{i}$')\nlabelLines(ax.get_lines())\nplt.show()","lang":"python","description":"Basic example: plot three lines and label them with automatic positioning."},"warnings":[{"fix":"Ensure every line you want labeled has a label string set via the 'label' parameter in plot.","message":"labelLines uses the line's label for text; if no label is set, it silently skips the line.","severity":"gotcha","affected_versions":"all"},{"fix":"Sort your data before plotting or use labelLine for manual control.","message":"labelLines positions labels based on the data range; if x or y data is not sorted, label placement may be unexpected.","severity":"gotcha","affected_versions":"all"},{"fix":"No change needed for labeling, but do not attempt to mutate ax.get_lines() directly.","message":"In matplotlib 3.7+, get_lines() returns an immutable sequence; modifying the returned list is no longer possible.","severity":"deprecated","affected_versions":">=0.8.1"},{"fix":"Use data coordinates for xvals, or convert using ax.transData.transform().","message":"The 'xvals' parameter expects x-coordinate values in data space; if you pass fractional axes coordinates, labels will be misplaced.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install via pip and use: from labellines import labelLines","cause":"Attempted import with wrong name (e.g., 'matplotlib_label_lines' or 'labellines' misspelled).","error":"ModuleNotFoundError: No module named 'labellines'"},{"fix":"Upgrade to latest version: pip install --upgrade matplotlib-label-lines","cause":"Older version of the library (before 0.6.0) used a different function name or the module is not installed correctly.","error":"ImportError: cannot import name 'labelLines' from 'labellines'"},{"fix":"Set label for each line: plt.plot(x, y, label='my line') or pass lines with labels only.","cause":"One or more lines in the collection do not have a label set (label is empty or None).","error":"KeyError: 'label' when calling labelLines"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}