Skip to content

Commit

Permalink
v0.6.1 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
scottshambaugh committed Jan 15, 2024
1 parent deecac3 commit fabe611
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
### Changed
### Removed

## [0.6.1] - 2024-01-14
### Added
* Testing
### Changed
* Fixed `axstereo.autoscale_z()` not doing anything if `zlim` was set

## [0.6.0] - 2024-01-14
### Added
* Church full color anaglyph example
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mpl_stereo"
version = "0.6.0"
version = "0.6.1"
description = "See your matplotlib plots in 3D by making stereograms and anaglyphs"
authors = ["Scott Shambaugh <[email protected]>"]
license = "MIT"
Expand Down
16 changes: 13 additions & 3 deletions src/mpl_stereo/AxesStereo.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def __init__(self,
self.zautoscale = True
if self.zlim is not None or zscale is not None:
self.zautoscale = False
self.is_redrawing = False

self.artists_left = []
self.artists_right = []
Expand Down Expand Up @@ -391,15 +392,22 @@ def autoscale_z(self):
"""
self.zautoscale = True
self.zlim = self._calc_bounding_zlim()
for _, _, kwargs in self.artist_args:
kwargs.pop('zlim', None)
self.redraw()

def _calc_bounding_zlim(self) -> tuple[float, float]:
"""
Calculate the z limits that will bound all the z data for all artists.
"""
zlim = (np.inf, -np.inf)
for _, _, kwargs in self.artist_args:
z = kwargs['z']
for _, args, kwargs in self.artist_args:
# Check if 'z' is in the keyword arguments or if there is a third
# argument of the same shape as x
if 'z' in kwargs:
z = kwargs['z']
elif len(args) > 0:
z, *args = args
zlim = (min(zlim[0], np.min(z)), max(zlim[1], np.max(z)))
return zlim

Expand All @@ -414,10 +422,12 @@ def redraw(self):
self.artists_right = []

# Plot the data again
self.is_redrawing = True
artist_args = self.artist_args
self.artist_args = [] # will repopulate in the getattr calls below
for name, args, kwargs in artist_args:
getattr(self, name)(*args, **kwargs)
self.is_redrawing = False

def plot2d(self,
ax_left: Axes,
Expand Down Expand Up @@ -492,7 +502,7 @@ def plot2d(self,
xlim=ax_left.get_xlim())
self.zscale = zscale
self.zlim = zlim
if len(self.artist_args) > 0:
if len(self.artist_args) > 0 and not self.is_redrawing:
self.redraw()

if isinstance(self, AxesStereo2D):
Expand Down
20 changes: 16 additions & 4 deletions tests/test_AxesStereo.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ def test_AxesAnaglyph_zlim():

assert axstereo.get_zlim() == (1, 2)

axstereo.autoscale_z() # will redraw
assert axstereo.zlim == (0, 9)

n_artists = 5 # from above plot()'s
assert len(axstereo.artists_left) == n_artists
assert len(axstereo.artists_right) == n_artists
Expand Down Expand Up @@ -210,10 +213,19 @@ def test_AxesAnaglyph():
assert True


def test_AxesAnaglyph_imshow_steroe():
# Smoke test imshow_stereo
axstereo = AxesAnaglyph()
axstereo.imshow_stereo(np.array([[1]]), np.array([[1]]))
def test_AxesAnaglyph_imshow_stereo():
# Smoke test imshow_stereo for scalar data
sun_left_data, sun_right_data = _testdata()['sun']
for cmap in [None, 'Oranges_r', 'viridis']:
axstereo = AxesAnaglyph()
axstereo.imshow_stereo(sun_left_data, sun_right_data, cmap=cmap)
assert True

# Smoke test imshow_stereo for RGB data
church_left_data, church_right_data = _testdata()['church']
for method in ['dubois', 'photoshop', 'photoshop2']:
axstereo = AxesAnaglyph()
axstereo.imshow_stereo(church_left_data, church_right_data, method=method)
assert True


Expand Down

0 comments on commit fabe611

Please sign in to comment.