Skip to main content

overlab

This is a function to prevent overlapping when annotating a plot in matplotlib. The algorithm works by starting from the coordinate to annotate and slowly moving the label in a spiral centered in the starting point progressively distancing from it until find a suitable place that is not overlapping any of the other labels.

The function is built on top of ax.annotate and takes the same **kwargs. The difference is that differently from ax.annotate that takes as argument single desired annotation and coordinates, overlab takes as arguments 3 iterables (x, y, and the list of labels) and the target ax).

Installation

The package can be installed with

pip install overlab 

Example

No overlab


import numpy as np
import matplotlib.pyplot as plt

# Fixing random state for reproducibility
np.random.seed(19680801)


N = 50
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
area = (30 * np.random.rand(N))**2  # 0 to 15 point radii
annotations=[f'label {str(n)}' for n in range(N)]

fig, ax = plt.subplots()
ax.scatter(x, y, s=area, c=colors, alpha=0.5)
for cordx, cordy, label in zip(x, y, annotations):
	ax.annotate(label,(cordx,cordy)) 

plt.show()

No_overlab

overlab

import numpy as np 
import matplotlib.pyplot as plt
import overlab as ol

# Fixing random state for reproducibility
np.random.seed(19680801)


N = 50
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
area = (30 * np.random.rand(N))**2  # 0 to 15 point radii
annotations=[f'label {str(n)}' for n in range(N)]

fig, ax = plt.subplots()
ax.scatter(x, y, s=area, c=colors, alpha=0.5)
ol.annoatate(x,y,annotations,ax=ax)

plt.show()

overlab

Metadata

Release files for overlab 0.2.5

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

Built distribution (wheel)

Table of built distributions (wheels) for overlab 0.2.5
File Interpreter ABI Platform Actions
overlab-0.2.5-py3-none-any.whl Python 3 none any Details for overlab-0.2.5-py3-none-any.whl

Release files / overlab-0.2.5-py3-none-any.whl

Download URL overlab-0.2.5-py3-none-any.whl
Size 15.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
10cf6bc1a7ee9b560b41bdd6c05b2ee9ff7ad1d6de9b19a6af57738091955fab
BLAKE2b-256 checksum
How to use checksums
af6589890c1f094556882b7f0d8e0e2ab5ac93ad96dc5cfc94e04e99330a6605
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Security for overlab 0.2.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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