Skip to main content

Label lines in matplotlib.

Project description

matplotlib-label-lines

Build status codecov

Easily label line(s) using matplotlib.

The code is heavily based on http://stackoverflow.com/questions/16992038/inline-labels-in-matplotlib (original code from NauticalMile).

Install

Just do:

pip install matplotlib-label-lines

You can try it online on binder Binder, get some inspiration from the example or from the following script:

import numpy as np
from matplotlib import pyplot as plt
from scipy.stats import chi2, loglaplace

from labellines import labelLine, labelLines

X = np.linspace(0, 1, 500)
A = [1, 2, 5, 10, 20]
funcs = [np.arctan, np.sin, loglaplace(4).pdf, chi2(5).pdf]

plt.subplot(321)
for a in A:
    plt.plot(X, np.arctan(a * X), label=str(a))

labelLines(plt.gca().get_lines(), zorder=2.5)

plt.subplot(322)
for a in A:
    plt.plot(X, np.sin(a * X), label=str(a))

labelLines(plt.gca().get_lines(), align=False, fontsize=14)

plt.subplot(323)
for a in A:
    plt.plot(X, loglaplace(4).pdf(a * X), label=str(a))

xvals = [0.8, 0.55, 0.22, 0.104, 0.045]
labelLines(plt.gca().get_lines(), align=False, xvals=xvals, color="k")

plt.subplot(324)
for a in A:
    plt.plot(X, chi2(5).pdf(a * X), label=str(a))

lines = plt.gca().get_lines()
l1 = lines[-1]
labelLine(
    l1,
    0.6,
    label=r"$Re=${}".format(l1.get_label()),
    ha="left",
    va="bottom",
    align=False,
    backgroundcolor='none'
)
labelLines(lines[:-1], yoffsets=0.01, align=False, backgroundcolor='none')

# labelLines also supports log-scaled x-axes
plt.subplot(325)
for a in A:
    plt.semilogx(X, np.arctan(5 * a * X), label=str(a))

labelLines(plt.gca().get_lines(), zorder=2.5)

plt.subplot(326)
for a in A:
    plt.semilogx(X, chi2(5).pdf(a * X), label=str(a))

labelLines(plt.gca().get_lines(), xvals=(0.1, 1), zorder=2.5)

plt.show()

Example

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matplotlib_label_lines-0.4.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matplotlib_label_lines-0.4.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file matplotlib_label_lines-0.4.1.tar.gz.

File metadata

  • Download URL: matplotlib_label_lines-0.4.1.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/50.3.2.post20201027 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9

File hashes

Hashes for matplotlib_label_lines-0.4.1.tar.gz
Algorithm Hash digest
SHA256 8bcab1a16d5ba0b64f8d19320293b52c875b8f45d35643b351b1a93e94616be4
MD5 80b76a800644f0fc6ec6246493b91ecc
BLAKE2b-256 e096c6c6f08bbd00c44ddb2faadf1b203c5a43e41a49eae85e556858d3c1e66e

See more details on using hashes here.

File details

Details for the file matplotlib_label_lines-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: matplotlib_label_lines-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/50.3.2.post20201027 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9

File hashes

Hashes for matplotlib_label_lines-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 03873064d706fcc8fce78f338f8d557438580247777638c2e544e277b745f691
MD5 650dc4baaaf44cbefbfe54da4f28d13b
BLAKE2b-256 6082195c768d3778a2213fb3fc582b152ea7b0b073d25586d7a83895f2b2da47

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page