Skip to main content

Natural extensions to Matplotlib for multidimensional plotting.

Project description

Matplotlib-extensions

Extends standard matplotlib plotting functions to higher dimensions with convenient and intuitive APIs. Higher dimensions can mean e.g. including time, color or multiple figure axes.

Extended functions:

time_scatter

time_scatter extends plt.scatter(x, y, OPTIONAL: z) to accept temporally dependent spatial samples x(t), y(t), OPTIONAL: z(t) and animates it. The arguments to time_scatter, thus, has shape shape(x(t)) = (N,T), compared to the purely spatial samples of scatter with shape shape(x) = (N,).

import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_swiss_roll
# sample some data (shape: (200,2))
data = make_swiss_roll(200, noise=0)[0][:, [0, 2]]
# sort data based on radial distance to origin
idxs = np.argsort(np.linalg.norm(data, axis=1))
data = data[idxs]

# Regular 2D scatter plot of data
fig, ax = plt.subplots()
ax.scatter(*data.T, alpha=0.2)

# Plot the same data, but over time using time_scatter
# the shape of data.T[:,None] is (2,1,200)
# meaning we display each sample at distinct timepoints
from mplextensions import time_scatter
time_scatter(*data.T[:,None], fps=24, fig=fig, ax=ax)

time_plot

time_plot extends plt.plot(x, y, OPTIONAL: z) to accept temporally dependent spatial samples x(t), y(t), OPTIONAL: z(t) and animates it. The arguments to time_plot, thus, has shape shape(x(t)) = (N,T), compared to the purely spatial samples of scatter with shape shape(x) = (N,).

import numpy as np
from mplextensions import time_plot

# Create a 2D sine wave
T = 100
x = np.linspace(0, 2 * np.pi, 200) # N=200
x_2d = np.tile(x[:, np.newaxis], (1, T))  # Shape: (N, T)
t_values = np.linspace(0, 2 * np.pi, T)
y_2d = np.sin(x_2d + t_values)  # Shape: (N, T)

time_plot(x_2d, y_2d)

time_imshow

time_imshow extends plt.imshow(X) to accept 3D images and animates it along the first dimension. The argument X to time_imshow, thus, has shape (T, H, W) or (T, H, W, C). Time, height, width, and optionally channels.

import numpy as np
from mplextensions import time_imshow

# create some 3D data
mesh = np.stack(np.meshgrid(*[np.linspace(-np.pi, np.pi, 32)]*3), axis=-1) # Shape: (32, 32, 32, 3)
mesh = np.exp(-np.linalg.norm(mesh, axis=-1)) # Shape: (32, 32, 32) => 3D Gaussian in (T, X, Y)

time_imshow(mesh, add_colorbar=True)

time_imshow

time_imshow extends plt.imshow(X) to accept 3D images and animates it along the first dimension. The argument X to time_imshow, thus, has shape (T, H, W) or (T, H, W, C). Time, height, width, and optionally channels.

import numpy as np
from mplextensions import time_imshow

# create some 3D data
mesh = np.stack(np.meshgrid(*[np.linspace(-np.pi, np.pi, 32)]*3), axis=-1) # Shape: (32, 32, 32, 3)
mesh = np.exp(-np.linalg.norm(mesh, axis=-1)) # Shape: (32, 32, 32) => 3D Gaussian in (T, X, Y)

time_imshow(mesh, add_colorbar=True)

multicolor_plot

multicolor_plot extends plt.plot(X) to accept a "values" parameter which colors the plot continuously.

import numpy as np
from mplextensions import multicolor_plot

x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x)
values = y

multicolor_plot(x, y)

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_extensions-0.2.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

matplotlib_extensions-0.2.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file matplotlib_extensions-0.2.0.tar.gz.

File metadata

  • Download URL: matplotlib_extensions-0.2.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for matplotlib_extensions-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8411bc836b3dcb562e74fcade93b5213fe54aa7757a4cb2679be83d4cfb3e181
MD5 cc1cde54e2c20a075fe9ed98d013009e
BLAKE2b-256 ed252d15d35b254c5d29e25c0bf2cc0462acf029669ccbad4f3c9ba0fdf6e4d6

See more details on using hashes here.

File details

Details for the file matplotlib_extensions-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for matplotlib_extensions-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 075b008459eb359ee1885aa5299fb7eb606d7c961af8d6f897599e3b4d789ba7
MD5 e7f4b91152ae04889175c49c19ef831a
BLAKE2b-256 a4c545f5929ecd9c4068913aa34588c97f51291cdb7350240cebf8ca44b88903

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