Skip to main content

codecov Tests

matplotlib_inline_labels

This package is inspired by matplotlib-label-lines

It adds automatic label positioning by preventing label bounding boxes from overlapping other lines and each other.

Install

Just do:

pip install matplotlib-inline-labels

Example

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

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

fig, axes = plt.subplots(ncols=2, nrows=3, constrained_layout=True, figsize=(8, 8))
axes = axes.flatten()

for a in A: 
    axes[0].plot(X, np.arctan(a * X), label=f"Line {a}")
add_inline_labels(axes[0], with_overall_progress=True, fontsize="large")

for a in A:
    axes[1].plot(X, np.sin(a * X), label=f"Line {a}")
    axes[2].plot(X, loglaplace(4).pdf(a * X), label=f"Line {a}")
    axes[3].plot(X, chi2(5).pdf(a * X), label=f"Line {a}")
    axes[4].semilogx(X, np.arctan(5 * a * X), label=str(a))
    axes[5].semilogx(X, chi2(5).pdf(a * X), label=str(a))
add_inline_labels(axes[1], with_overall_progress=True, fontsize="x-small")
add_inline_labels(axes[2], with_overall_progress=True, fontsize="medium")
add_inline_labels(axes[3], with_overall_progress=True, fontsize="medium")
add_inline_labels(axes[4], with_overall_progress=True, fontsize="small")
add_inline_labels(axes[5], with_overall_progress=True, fontsize="small")

fig.show()

Example

Visual debug

If something goes wrong or the automatic placement could be enhanced, a visual debug is available:

fig, ax = plt.subplots()

for a in A: 
    ax.semilogx(X, chi2(5).pdf(a * X), label=f"Line {a}")
ax.set_ylim(top=0.12)
fig_debug = add_inline_labels(ax, ppf=1.5, with_perlabel_progress=True, debug=True)

fig_debug.show()

Visual debug example

TODO

  • Handle the case of axis lims or scale modification after adding inline labels
  • Create an option to search label's position keeping the label's bounding box sides intersecting the curve in their centers
  • Avoid Line2D labels to overlap non Line2D objects -> Needs to build geometries for other objects

Metadata

Release files for matplotlib-inline-labels 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for matplotlib-inline-labels 0.2.2
File Size Uploaded
matplotlib_inline_labels-0.2.2.tar.gz 30.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for matplotlib-inline-labels 0.2.2
File Interpreter ABI Platform
matplotlib_inline_labels-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 64.6 kB

Release files / matplotlib_inline_labels-0.2.2.tar.gz

Download URL matplotlib_inline_labels-0.2.2.tar.gz
Size 30.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b7756e71c33f8afe950da87354c30e8394f6913d3b52ff7b0c59ed58710d1525
BLAKE2b-256 checksum
How to use checksums
6d0a5cbd41222450b78d04ff5caf9d0359110e3d8821ec3d066f6e123d93dc77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / matplotlib_inline_labels-0.2.2-py3-none-any.whl

Download URL matplotlib_inline_labels-0.2.2-py3-none-any.whl
Size 34.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7700aee91fb05a78265407c255fe5b1f1103493dc5215bb639a307fff968bd3a
BLAKE2b-256 checksum
How to use checksums
1a62b17b8f5ae3c7dba871a6afe76846d43129d8bb48e1dc96c5fd7cd94bd76b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page