No project description provided
Project description
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()
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()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file overlab-0.2.5-py3-none-any.whl
.
File metadata
- Download URL: overlab-0.2.5-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10cf6bc1a7ee9b560b41bdd6c05b2ee9ff7ad1d6de9b19a6af57738091955fab |
|
MD5 | d80bae3d0e896f4b4acbe5560cb93924 |
|
BLAKE2b-256 | af6589890c1f094556882b7f0d8e0e2ab5ac93ad96dc5cfc94e04e99330a6605 |