Skip to main content

PCA 3D Visualizations

This module produces informative visualizations of atleast 3-dimensional data, optionally using principal component analysis and automatic clustering.

Features

  • Animated: high-quality videos with multi-processed video production using pympanim.
  • (Pdf) snapshots that can be used in research papers or where the full video cannot be used.
  • Supports automatic clustering for informative zooms
  • Supports trajectories of data, for example for visualizing data through time for a recurrent network or through layers of a feedforward network.
  • Supports using different markers, in any combination of style and color

Installation

This package requires ffmpeg to be installed.

pip install pca3dvis

Example Videos

examples/gaus_balls.py

https://youtu.be/n9rpWhuN6LA

examples/all_rand.py

https://www.youtube.com/watch?v=YnIRqSQ8lAU

Usage

Video introduction at https://youtu.be/JqfVY9pdxY8

Projecting to 3D from higher dimensions

There are many approaches for projecting to 3-dimensions. Once you have used any of these projections, you can use this library to visualize the resulting 3d scatter plot.

This library provides one linear projection that depends on the eigenvectors of the covariance matrix, called principal component analysis. For more information see Wold, Esbensen, and Geladi, 1987

To quickly generate a pca3dvis.trajectory.ProjectedTrajectory using this technique for an arbitrary ndarray[samples, features] where features > 3, the following snippet will work:

import numpy as np
import pca3dvis.pcs as pcs

data: np.ndarray # must have shape [samples > 3, features > 3]
lbls: np.ndarray # must have shape [samples = data.shape[0], ...]
traj = pcs.get_pc_trajectory([data], lbls)

This creates a trajectory with a single snapshot; for multiple snapshots, just have [data] instead be a list of ndarrays which each have the same number of samples but possibly different numbers of features.

Converting 3D data to trajectories

A trajectory is a sequence of one or more snapshots which have the same labels. They include the projection matrix that created them from the original data. For quickly plotting already projected data, the labels can be swapped with all zeros of the appropriate shape and the projection matrix with the identity map.

import numpy as np
import pca3dvis.snapshot
import pca3dvis.trajectory

raw_data: np.ndarray # must have shape [samples > 3, og_features]
proj_matrices: np.ndarray # must have shape [og_features, 3]
lbls: np.ndarray # must have shape [samples = data.shape[0], ...]
snap = pca3dvis.snapshot.project_with_matrix(raw_data, lbls, proj_matrices)

traj = pca3dvis.trajectory.ProjectedTrajectory([snap]) # trajectory of one snap

Plotting trajectories

Plotting trajectories, the main feature of this module, requires only that you give a name to each snapshot and give markers to each label.

Markers are described as follows: Suppose there are N samples and M distinct styles. Then for each style m, you will create a bool numpy array with shape (N,) mask where mask[i] is True if sample[i] should be rendered with style m. The style is described with a dict which are the keyword arguments to scatter. It should at least specifiy the size and color (s and c respectively), and it may use a colormap to do so, but if it does it must specify the norm exactly, i.e., with vmin and vmax not None.

For a more complete example of styling, see examples/gaus_balls.py.

import numpy as np
import pca3dvis.trajectory
import pca3dvis.worker

traj: pca3dvis.trajectory.ProjectedTrajectory
titles = [f'Snapshot {i+1}' for i in range(traj.num_snapshots)]
markers = [(
    np.ones(traj.num_samples, 'bool'),
    {'s': 20, 'c': 'tab:red'}
)]
pca3dvis.worker.generate(traj, markers, titles, 'out/my_out_folder',
                         draft=True, clusters=True)

Metadata

Release files for pca3dvis 0.0.3

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

Source distribution (sdist)

Source distribution for pca3dvis 0.0.3
File Size Uploaded Provenance Actions
pca3dvis-0.0.3.tar.gz 16.0 kB Without provenance Details for pca3dvis-0.0.3.tar.gz

Built distribution (wheel)

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

Total release size: 36.6 kB

Release files / pca3dvis-0.0.3.tar.gz

Download URL pca3dvis-0.0.3.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1c4e0a65156af7aa0bc672e50d3655128dc42c8f45a156ddb5f3a6b90d6da6d5
BLAKE2b-256 checksum
How to use checksums
d2b73a906b6493af4e594f280827197ee25b65dc74ba1466b0880e58c4e270d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.0

Release files / pca3dvis-0.0.3-py3-none-any.whl

Download URL pca3dvis-0.0.3-py3-none-any.whl
Size 20.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c5b75866a62c9ed588e4a2fbd13b81b0dcd163fe5bdbccf3047d7930a0ce1515
BLAKE2b-256 checksum
How to use checksums
01f09dbb1f1e41d261550042d3205f0b390a01a6f050cbb75cfed12fc8eb1c14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.0

Security for pca3dvis 0.0.3

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