Skip to content

Commit aea17cf

Browse files
Begin work on adding 3d support.
1 parent a574f9c commit aea17cf

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

matplotview/_transform_renderer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ def __init__(
7878
f"Invalid Interpolation Mode: {image_interpolation}"
7979
)
8080

81+
@property
82+
def bounding_axes(self):
83+
return self.__bounding_axes
84+
8185
def _scale_gc(self, gc):
8286
transfer_transform = self._get_transfer_transform(IdentityTransform())
8387
new_gc = self.__renderer.new_gc()
@@ -188,6 +192,8 @@ def draw_path(self, gc, path, transform, rgbFace=None):
188192
# Change the clip to the sub-axes box
189193
gc.set_clip_rectangle(bbox)
190194

195+
rgbFace = tuple(rgbFace) if(rgbFace is not None) else None
196+
191197
self.__renderer.draw_path(gc, path, IdentityTransform(), rgbFace)
192198

193199
def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath):

matplotview/_view_axes.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
DEFAULT_RENDER_DEPTH = 5
1111

1212
class BoundRendererArtist:
13-
def __init__(self, artist: Artist, renderer: RendererBase, clip_box: Bbox):
13+
def __init__(
14+
self,
15+
artist: Artist,
16+
renderer: _TransformRenderer,
17+
clip_box: Bbox
18+
):
1419
self._artist = artist
1520
self._renderer = renderer
1621
self._clip_box = clip_box
@@ -34,6 +39,16 @@ def draw(self, renderer: RendererBase):
3439
full_extents = self._artist.get_window_extent(self._renderer)
3540
self._artist.set_clip_box(full_extents)
3641

42+
# If we are working with a 3D object, swap out it's axes with
43+
# this zoom axes (swapping out the 3d transform) and reproject it.
44+
if(hasattr(self._artist, "do_3d_projection")):
45+
ax = self._artist.axes
46+
self._artist.axes = None
47+
self._artist.axes = self._renderer.bounding_axes
48+
self._artist.do_3d_projection()
49+
self._artist.axes = None
50+
self._artist.axes = ax
51+
3752
# Check and see if the passed limiting box and extents of the
3853
# artist intersect, if not don't bother drawing this artist.
3954
if(Bbox.intersection(full_extents, self._clip_box) is not None):

matplotview/tests/test_inset_zoom.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,32 @@ def test_plotting_in_view(fig_test, fig_ref):
104104
"Interesting", (3, 3), (0, 0),
105105
textcoords="axes fraction", arrowprops=arrow_s
106106
)
107-
ax_ref.indicate_inset_zoom(axins_ref, edgecolor="black")
107+
ax_ref.indicate_inset_zoom(axins_ref, edgecolor="black")
108+
109+
110+
@check_figures_equal()
111+
def test_3d_view(fig_test, fig_ref):
112+
# The data...
113+
X = Y = np.arange(-5, 5, 0.25)
114+
X, Y = np.meshgrid(X, Y)
115+
Z = np.sin(np.sqrt(X ** 2 + Y ** 2))
116+
117+
# Test Case...
118+
ax1_test, ax2_test = fig_test.subplots(
119+
1, 2, subplot_kw=dict(projection="3d")
120+
)
121+
ax1_test.plot_surface(X, Y, Z)
122+
view(ax2_test, ax1_test)
123+
ax2_test.set_xlim(-10, 10)
124+
ax2_test.set_ylim(-10, 10)
125+
ax2_test.set_zlim(-2, 2)
126+
127+
# Reference
128+
ax1_ref, ax2_ref = fig_ref.subplots(
129+
1, 2, subplot_kw=dict(projection="3d")
130+
)
131+
ax1_ref.plot_surface(X, Y, Z)
132+
ax2_ref.plot_surface(X, Y, Z)
133+
ax2_ref.set_xlim(-10, 10)
134+
ax2_ref.set_ylim(-10, 10)
135+
ax2_ref.set_zlim(-2, 2)

0 commit comments

Comments
 (0)