mpl-scatter-density¶
mpl-scatter-density facilitates the creation of interactive scatter density maps from large amounts of data.
Installation¶
$ pipenv install mpl-scatter-density
This automatically installs the dependencies Numpy, Matplotlib and fast-histogram.
Intended use¶
Imports
[1]:
import matplotlib.pyplot as plt
import mpl_scatter_density
import numpy as np
Generate sample data
[2]:
N = 10000000
x = np.random.normal(4, 2, N)
y = np.random.normal(3, 1, N)
There are essentially two uses for mpl-scatter-density:
projection='scatter_density'
ScatterDensityArtist
projection='scatter_density'
[3]:
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection="scatter_density")
ax.scatter_density(x, y)
ax.set_xlim(-5, 10)
ax.set_ylim(-5, 10)
fig.savefig("gaussian.png")
/Users/veit/.local/share/virtualenvs/python-311-6zxVKbDJ/lib/python3.11/site-packages/mpl_scatter_density/generic_density_artist.py:77: RuntimeWarning: All-NaN slice encountered
vmin = self._density_vmin(array)
/Users/veit/.local/share/virtualenvs/python-311-6zxVKbDJ/lib/python3.11/site-packages/mpl_scatter_density/generic_density_artist.py:82: RuntimeWarning: All-NaN slice encountered
vmax = self._density_vmax(array)

ScatterDensityArtist
ScatterDensityArtist
is also used in the previous example, but without specifying it directly. In the following example, we add it explicitly to the axes:
[4]:
from mpl_scatter_density import ScatterDensityArtist
a = ScatterDensityArtist(ax, x, y)
ax.add_artist(a)
[4]:
<mpl_scatter_density.scatter_density_artist.ScatterDensityArtist at 0x10bc0f150>