Skip to content

Commit 4f93e0c

Browse files
committed
Add two tests for mutating input arrays #8990
update test for #8990 update test for #8990
1 parent 871958c commit 4f93e0c

File tree

2 files changed

+49
-112
lines changed

2 files changed

+49
-112
lines changed

lib/matplotlib/tests/test_mutate_inputs.py

Lines changed: 0 additions & 112 deletions
This file was deleted.

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,3 +2124,52 @@ def test_panecolor_rcparams():
21242124
'axes3d.zaxis.panecolor': 'b'}):
21252125
fig = plt.figure(figsize=(1, 1))
21262126
fig.add_subplot(projection='3d')
2127+
2128+
2129+
# test cases came from GH#8990
2130+
@check_figures_equal(extensions=["png"])
2131+
def test_mutating_input_arrays_y_and_z(fig_test, fig_ref):
2132+
ax1 = fig_test.add_subplot(111, projection='3d')
2133+
x = [1, 2, 3]
2134+
y = [0.0, 0.0, 0.0]
2135+
z = [0.0, 0.0, 0.0]
2136+
ax1.plot(x, y, z, 'o-')
2137+
2138+
ax1.set_ylim([0, 4])
2139+
ax1.set_zlim([0, 4])
2140+
fig_test.draw_without_rendering()
2141+
2142+
# mutate y,z to get a nontrivial line
2143+
y[:] = [1, 2, 3]
2144+
z[:] = [1, 2, 3]
2145+
fig_test.draw_without_rendering()
2146+
2147+
# draw the same plot without mutating x and y
2148+
ax2 = fig_ref.add_subplot(111, projection='3d')
2149+
x = [1, 2, 3]
2150+
y = [0.0, 0.0, 0.0]
2151+
z = [0.0, 0.0, 0.0]
2152+
ax2.plot(x, y, z, 'o-')
2153+
2154+
ax2.set_ylim([0, 4])
2155+
ax2.set_zlim([0, 4])
2156+
2157+
2158+
# test cases came from GH#8990
2159+
@check_figures_equal(extensions=["png"])
2160+
def test_mutating_input_arrays_sin_3d(fig_test, fig_ref):
2161+
x = np.arange(0, 2*np.pi, 0.1)
2162+
v1 = np.zeros_like(x)
2163+
ax1 = fig_test.subplots(subplot_kw={'projection': '3d'}) # 3D plot
2164+
v1[:] = np.sin(x)
2165+
ax1.plot(x, v1, zs=1, zdir='y')
2166+
v1[:] = np.sin(5*x)
2167+
ax1.plot(x, v1, zs=2, zdir='y')
2168+
2169+
# plotting the same graph without changing any data
2170+
x1 = np.arange(0, 2*np.pi, 0.1)
2171+
v2 = np.sin(x1)
2172+
v3 = np.sin(5*x1)
2173+
ax2 = fig_ref.subplots(subplot_kw={'projection': '3d'}) # 3D plot
2174+
ax2.plot(x1, v2, zs=1, zdir='y')
2175+
ax2.plot(x1, v3, zs=2, zdir='y')

0 commit comments

Comments
 (0)