Skip to content

Fix mplot3d projection #8896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 7, 2020
Prev Previous commit
Next Next commit
TST: Change tests to use default styles
As requested in review feedback - since all the images changed, may as well
restyle them.

Note that this restyling caused a test to become platform-dependent on the
anti-aliasing on the edges of a narrow line - presumably due to the resolution
decrease making the line narrower - so a non-zero `tol` value was added.
  • Loading branch information
eric-wieser committed Jun 24, 2019
commit c6416078f39ab3ae3da7c761ca28e1ec707722b5
101 changes: 66 additions & 35 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def test_aspect_equal_error():
ax.set_aspect('equal')


@image_comparison(['bar3d.png'], remove_text=True)
@image_comparison(['bar3d.png'],
remove_text=True, style='default')
def test_bar3d():
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
Expand All @@ -30,7 +31,8 @@ def test_bar3d():
ax.bar(xs, ys, zs=z, zdir='y', align='edge', color=cs, alpha=0.8)


@image_comparison(['bar3d_shaded.png'], remove_text=True)
@image_comparison(['bar3d_shaded.png'],
remove_text=True, style='default')
def test_bar3d_shaded():
x = np.arange(4)
y = np.arange(5)
Expand All @@ -50,7 +52,8 @@ def test_bar3d_shaded():
fig.canvas.draw()


@image_comparison(['bar3d_notshaded.png'], remove_text=True)
@image_comparison(['bar3d_notshaded.png'],
remove_text=True, style='default')
def test_bar3d_notshaded():
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
Expand All @@ -63,7 +66,8 @@ def test_bar3d_notshaded():
fig.canvas.draw()


@image_comparison(['contour3d.png'], remove_text=True, style='mpl20')
@image_comparison(['contour3d.png'],
remove_text=True, style='default')
def test_contour3d():
fig = plt.figure()
ax = fig.gca(projection='3d')
Expand All @@ -76,7 +80,8 @@ def test_contour3d():
ax.set_zlim(-100, 100)


@image_comparison(['contourf3d.png'], remove_text=True)
@image_comparison(['contourf3d.png'],
remove_text=True, style='default')
def test_contourf3d():
fig = plt.figure()
ax = fig.gca(projection='3d')
Expand All @@ -89,7 +94,8 @@ def test_contourf3d():
ax.set_zlim(-100, 100)


@image_comparison(['contourf3d_fill.png'], remove_text=True)
@image_comparison(['contourf3d_fill.png'],
remove_text=True, style='default')
def test_contourf3d_fill():
fig = plt.figure()
ax = fig.gca(projection='3d')
Expand All @@ -104,7 +110,8 @@ def test_contourf3d_fill():
ax.set_zlim(-1, 1)


@image_comparison(['tricontour.png'], remove_text=True, style='mpl20')
@image_comparison(['tricontour.png'],
remove_text=True, style='default')
def test_tricontour():
fig = plt.figure()

Expand All @@ -119,7 +126,8 @@ def test_tricontour():
ax.tricontourf(x, y, z)


@image_comparison(['lines3d.png'], remove_text=True)
@image_comparison(['lines3d.png'],
remove_text=True, style='default')
def test_lines3d():
fig = plt.figure()
ax = fig.gca(projection='3d')
Expand All @@ -131,7 +139,8 @@ def test_lines3d():
ax.plot(x, y, z)


@image_comparison(['mixedsubplot.png'], remove_text=True)
@image_comparison(['mixedsubplot.png'],
remove_text=True, style='default')
def test_mixedsubplots():
def f(t):
return np.cos(2*np.pi*t) * np.exp(-t)
Expand Down Expand Up @@ -168,7 +177,8 @@ def test_tight_layout_text(fig_test, fig_ref):
ax2.text(.5, .5, .5, s='some string')


@image_comparison(['scatter3d.png'], remove_text=True)
@image_comparison(['scatter3d.png'],
remove_text=True, style='default')
def test_scatter3d():
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
Expand All @@ -178,7 +188,8 @@ def test_scatter3d():
c='b', marker='^')


@image_comparison(['scatter3d_color.png'], remove_text=True)
@image_comparison(['scatter3d_color.png'],
remove_text=True, style='default')
def test_scatter3d_color():
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
Expand All @@ -188,7 +199,8 @@ def test_scatter3d_color():
color='b', marker='s')


@image_comparison(['plot_3d_from_2d.png'], remove_text=True)
@image_comparison(['plot_3d_from_2d.png'],
remove_text=True, style='default', tol=0.01)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anntzer, fix was to add this tol argument, as mentioned in the commit. Actual RMS was 0.008, so this seemed a reasonable choice

def test_plot_3d_from_2d():
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
Expand All @@ -198,7 +210,8 @@ def test_plot_3d_from_2d():
ax.plot(xs, ys, zs=0, zdir='y')


@image_comparison(['surface3d.png'], remove_text=True)
@image_comparison(['surface3d.png'],
remove_text=True, style='default')
def test_surface3d():
fig = plt.figure()
ax = fig.gca(projection='3d')
Expand All @@ -213,7 +226,8 @@ def test_surface3d():
fig.colorbar(surf, shrink=0.5, aspect=5)


@image_comparison(['surface3d_shaded.png'], remove_text=True)
@image_comparison(['surface3d_shaded.png'],
remove_text=True, style='default')
def test_surface3d_shaded():
fig = plt.figure()
ax = fig.gca(projection='3d')
Expand All @@ -227,7 +241,7 @@ def test_surface3d_shaded():
ax.set_zlim(-1.01, 1.01)


@image_comparison(['text3d.png'])
@image_comparison(['text3d.png'], style='default')
def test_text3d():
fig = plt.figure()
ax = fig.gca(projection='3d')
Expand All @@ -251,7 +265,8 @@ def test_text3d():
ax.set_zlabel('Z axis')


@image_comparison(['trisurf3d.png'], remove_text=True, tol=0.03)
@image_comparison(['trisurf3d.png'],
remove_text=True, tol=0.03, style='default')
def test_trisurf3d():
n_angles = 36
n_radii = 8
Expand All @@ -269,7 +284,8 @@ def test_trisurf3d():
ax.plot_trisurf(x, y, z, cmap=cm.jet, linewidth=0.2)


@image_comparison(['trisurf3d_shaded.png'], remove_text=True, tol=0.03)
@image_comparison(['trisurf3d_shaded.png'],
remove_text=True, tol=0.03, style='default')
def test_trisurf3d_shaded():
n_angles = 36
n_radii = 8
Expand All @@ -287,23 +303,26 @@ def test_trisurf3d_shaded():
ax.plot_trisurf(x, y, z, color=[1, 0.5, 0], linewidth=0.2)


@image_comparison(['wireframe3d.png'], remove_text=True)
@image_comparison(['wireframe3d.png'],
remove_text=True, style='default')
def test_wireframe3d():
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
ax.plot_wireframe(X, Y, Z, rcount=13, ccount=13)


@image_comparison(['wireframe3dzerocstride.png'], remove_text=True)
@image_comparison(['wireframe3dzerocstride.png'],
remove_text=True, style='default')
def test_wireframe3dzerocstride():
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
ax.plot_wireframe(X, Y, Z, rcount=13, ccount=0)


@image_comparison(['wireframe3dzerorstride.png'], remove_text=True)
@image_comparison(['wireframe3dzerorstride.png'],
remove_text=True, style='default')
def test_wireframe3dzerorstride():
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
Expand All @@ -329,7 +348,8 @@ def test_mixedsamplesraises():
ax.plot_surface(X, Y, Z, cstride=50, rcount=10)


@image_comparison(['quiver3d.png'], remove_text=True)
@image_comparison(['quiver3d.png'],
remove_text=True, style='default')
def test_quiver3d():
fig = plt.figure()
ax = fig.gca(projection='3d')
Expand All @@ -344,7 +364,8 @@ def test_quiver3d():
ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tip', normalize=True)


@image_comparison(['quiver3d_empty.png'], remove_text=True)
@image_comparison(['quiver3d_empty.png'],
remove_text=True, style='default')
def test_quiver3d_empty():
fig = plt.figure()
ax = fig.gca(projection='3d')
Expand All @@ -359,7 +380,8 @@ def test_quiver3d_empty():
ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tip', normalize=True)


@image_comparison(['quiver3d_masked.png'], remove_text=True)
@image_comparison(['quiver3d_masked.png'],
remove_text=True, style='default')
def test_quiver3d_masked():
fig = plt.figure()
ax = fig.gca(projection='3d')
Expand All @@ -378,7 +400,8 @@ def test_quiver3d_masked():
ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tip', normalize=True)


@image_comparison(['quiver3d_pivot_middle.png'], remove_text=True)
@image_comparison(['quiver3d_pivot_middle.png'],
remove_text=True, style='default')
def test_quiver3d_pivot_middle():
fig = plt.figure()
ax = fig.gca(projection='3d')
Expand All @@ -393,7 +416,8 @@ def test_quiver3d_pivot_middle():
ax.quiver(x, y, z, u, v, w, length=0.1, pivot='middle', normalize=True)


@image_comparison(['quiver3d_pivot_tail.png'], remove_text=True)
@image_comparison(['quiver3d_pivot_tail.png'],
remove_text=True, style='default')
def test_quiver3d_pivot_tail():
fig = plt.figure()
ax = fig.gca(projection='3d')
Expand All @@ -408,7 +432,8 @@ def test_quiver3d_pivot_tail():
ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tail', normalize=True)


@image_comparison(['poly3dcollection_closed.png'], remove_text=True)
@image_comparison(['poly3dcollection_closed.png'],
remove_text=True, style='default')
def test_poly3dcollection_closed():
fig = plt.figure()
ax = fig.gca(projection='3d')
Expand All @@ -430,7 +455,8 @@ def test_poly_collection_2d_to_3d_empty():
assert poly.get_paths() == []


@image_comparison(['poly3dcollection_alpha.png'], remove_text=True)
@image_comparison(['poly3dcollection_alpha.png'],
remove_text=True, style='default')
def test_poly3dcollection_alpha():
fig = plt.figure()
ax = fig.gca(projection='3d')
Expand All @@ -447,7 +473,7 @@ def test_poly3dcollection_alpha():
ax.add_collection3d(c2)


@image_comparison(['axes3d_labelpad.png'])
@image_comparison(['axes3d_labelpad.png'], style='default')
def test_axes3d_labelpad():
from matplotlib import rcParams

Expand All @@ -469,7 +495,7 @@ def test_axes3d_labelpad():
tick.set_pad(tick.get_pad() - i * 5)


@image_comparison(['axes3d_cla.png'])
@image_comparison(['axes3d_cla.png'], style='default')
def test_axes3d_cla():
# fixed in pull request 4553
fig = plt.figure()
Expand Down Expand Up @@ -540,7 +566,8 @@ def _test_proj_draw_axes(M, s=1, *args, **kwargs):
return fig, ax


@image_comparison(['proj3d_axes_cube.png'], remove_text=True, style='default')
@image_comparison(['proj3d_axes_cube.png'],
remove_text=True, style='default')
def test_proj_axes_cube():
M = _test_proj_make_M()

Expand Down Expand Up @@ -672,7 +699,8 @@ def test_invalid_axes_limits(setter, side, value):


class TestVoxels:
@image_comparison(['voxels-simple.png'], remove_text=True)
@image_comparison(['voxels-simple.png'],
remove_text=True, style='default')
def test_simple(self):
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})

Expand All @@ -692,7 +720,8 @@ def test_edge_style(self):
# change the edge color of one voxel
v[max(v.keys())].set_edgecolor('C2')

@image_comparison(['voxels-named-colors.png'], remove_text=True)
@image_comparison(['voxels-named-colors.png'],
remove_text=True, style='default')
def test_named_colors(self):
"""Test with colors set to a 3d object array of strings."""
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
Expand All @@ -705,7 +734,8 @@ def test_named_colors(self):
colors[(x + z) < 10] = 'cyan'
ax.voxels(voxels, facecolors=colors)

@image_comparison(['voxels-rgb-data.png'], remove_text=True)
@image_comparison(['voxels-rgb-data.png'],
remove_text=True, style='default')
def test_rgb_data(self):
"""Test with colors set to a 4d float array of rgb data."""
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
Expand All @@ -718,7 +748,8 @@ def test_rgb_data(self):
colors[..., 2] = z / 9
ax.voxels(voxels, facecolors=colors)

@image_comparison(['voxels-alpha.png'], remove_text=True)
@image_comparison(['voxels-alpha.png'],
remove_text=True, style='default')
def test_alpha(self):
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})

Expand All @@ -736,7 +767,7 @@ def test_alpha(self):
assert voxels[coord], "faces returned for absent voxel"
assert isinstance(poly, art3d.Poly3DCollection)

@image_comparison(['voxels-xyz.png'], tol=0.01)
@image_comparison(['voxels-xyz.png'], tol=0.01, style='default')
def test_xyz(self):
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})

Expand Down