See your matplotlib plots in 3D by making stereograms
Project description
mpl_stereo
Matplotlib add-on to make stereograms.
Stereograms can significantly enhance the interpretability of 3D data by leveraging human binocular vision. Instead of looking at a flat projection on a page, stereograms give us "3D glasses" for 2D data with just our eyes.
It takes some practice to be able to view the stereoscopic effect for the first time, but the effort is well worth it!
Usage
Installation
pip install mpl_stereo
Setup
import numpy as np
from mpl_stereo import AxesStereo2D, AxesStereo3D
# Generate some data, we'll make a trefoil knot
t = np.linspace(0, 2*np.pi, 100)
x = np.cos(2*t) * (3 + np.cos(3*t))
y = np.sin(2*t) * (3 + np.cos(3*t))
z = np.sin(3*t)
2D plots
Currently, only a subset of matplotlib's 2D plots are officially supported. See the list in axstereo.known_methods
.
axstereo = AxesStereo2D()
axstereo.plot(x, y, z, c='k', alpha=0.2)
axstereo.scatter(x, y, z, c=z, cmap='viridis', s=10)
When you are viewing the stereogram properly, you should see the knot weave in and out of the page!
Warning: Please note that for 2D plots the stereoscopic effect requires shifting data, so the data will not necessarily line up with the axis labels! Right now this is controlled with the focal_plane
parameter. Calling AxesStereo2D(focal_plane=-1)
(the default) will ensure that the left axes data is not shifted, whereas AxesStereo2D(focal_plane=1)
will lock down the right axes data. The tick labels for axes where the data is not aligned will have transparency applied. So in the plot above, the right side labels being lighter gray indicates that you should not trust that data to be positioned correctly, but the left subplot with its black labeling is accurate.
3D plots
The stereoscopic effect in 3D is made just by rotating the plot view, so all of matplotlib's 3D plot types are supported, and there are no concerns about data not lining up with the axis labels.
axstereo = AxesStereo3D()
axstereo.plot(x, y, z, c='k', alpha=0.2)
axstereo.scatter(x, y, z, c=z, cmap='viridis', s=10)
Working With Plots
Calling any method on an AxesStereo2D
or AxesStereo3D
object will pass that method call onto both of the left and right subplot axes. In the 2D case, the plotting methods which take in x
and y
arguments are intercepted and the additional z
data is processed to obtain appropriate horizontal offsets.
The figure and two subplot axes can be accessed with the following:
axstereo.fig
axstereo.ax_left
axstereo.ax_right
Viewing Stereograms
These are not autostereograms, like the "Magic Eye" books that were popular in the 1990's. However, they use the same viewing technique. Below is ChatGPT's how-to guide on viewing these, but I'll try to find a better beginner-friendly resource to put here.
- Position the Stereogram: Place it at arm's length and ensure it's level with your eyes.
- Relax Your Focus: Look through the image, as if focusing on something distant, rather than the stereogram itself.
- Parallel Viewing: Try to view the image with your eyes parallel, similar to how you would look at a distant object.
- Align and Overlap: Adjust the angle and distance of the stereogram until the two images begin to overlap.
- Perceive the 3D Image: As the images overlap, a 3D image should emerge. Keep your focus steady to maintain the illusion.
- Practice: If initially unsuccessful, take breaks and try again. It might require some practice to get used to this method.
Parallel vs Cross-Eyed Viewing
By default, the stereograms are set up for "parallel" viewing method as described above. For "cross-eyed" viewing, initialize with a negative ipd
parameter. An ipd (Inter-Pupilary Distance) of 65 millimeters is the default, so call AxesStereo2D(ipd=-65)
for the default cross-eyed viewing.
Derivation of Geometry
TODO
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 Distribution
Built Distribution
File details
Details for the file mpl_stereo-0.1.2.tar.gz
.
File metadata
- Download URL: mpl_stereo-0.1.2.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.8.10 Linux/5.10.102.1-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22f54e02d2881bde2d509aebacd40823d224884906d45493159dc21ee0389433 |
|
MD5 | 494a77b114c4ac45fd95aa9fe9684c1e |
|
BLAKE2b-256 | bd261775f9c8364bbc15a28b24bd1777087a58fdeba7287fb004a34ebcd815d4 |
Provenance
File details
Details for the file mpl_stereo-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: mpl_stereo-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.8.10 Linux/5.10.102.1-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5cac18597cd05713c4f55022fa8e4c5de9dfc7e3060259b25165424aedf5ed7 |
|
MD5 | 4f91bfcfedf8f248f72c94dc3a02f3f1 |
|
BLAKE2b-256 | 2c7dff00ae4a65fe7e6dfc7b430f2b23a52ba00ae503a51a296d7b79533f7ea7 |