diff --git a/pygmt/tests/baseline/test_plot3d_colors.png.dvc b/pygmt/tests/baseline/test_plot3d_colors.png.dvc new file mode 100644 index 00000000000..4f80f1176a2 --- /dev/null +++ b/pygmt/tests/baseline/test_plot3d_colors.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 9ed4293beb77a27cecba15658af20d1d + size: 30701 + path: test_plot3d_colors.png diff --git a/pygmt/tests/baseline/test_plot3d_colors_sizes.png.dvc b/pygmt/tests/baseline/test_plot3d_colors_sizes.png.dvc new file mode 100644 index 00000000000..0a8534d8b3d --- /dev/null +++ b/pygmt/tests/baseline/test_plot3d_colors_sizes.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: ea0653b5ecb03d71872bfff1f90e77b1 + size: 29285 + path: test_plot3d_colors_sizes.png diff --git a/pygmt/tests/baseline/test_plot3d_colors_sizes_proj.png.dvc b/pygmt/tests/baseline/test_plot3d_colors_sizes_proj.png.dvc new file mode 100644 index 00000000000..d7ffd6ed30a --- /dev/null +++ b/pygmt/tests/baseline/test_plot3d_colors_sizes_proj.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 05fb4a508f11db7ad8266532b609446a + size: 56253 + path: test_plot3d_colors_sizes_proj.png diff --git a/pygmt/tests/baseline/test_plot3d_from_file.png.dvc b/pygmt/tests/baseline/test_plot3d_from_file.png.dvc new file mode 100644 index 00000000000..048b2a16274 --- /dev/null +++ b/pygmt/tests/baseline/test_plot3d_from_file.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 1c42135d58b8ea4d3dc6aa0cb9a45f9d + size: 53113 + path: test_plot3d_from_file.png diff --git a/pygmt/tests/baseline/test_plot3d_matrix.png.dvc b/pygmt/tests/baseline/test_plot3d_matrix.png.dvc new file mode 100644 index 00000000000..4d6503c1eb1 --- /dev/null +++ b/pygmt/tests/baseline/test_plot3d_matrix.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 1506c5fc33859e7f699e5421c3429ce9 + size: 39041 + path: test_plot3d_matrix.png diff --git a/pygmt/tests/baseline/test_plot3d_matrix_color.png.dvc b/pygmt/tests/baseline/test_plot3d_matrix_color.png.dvc new file mode 100644 index 00000000000..6c85841e3b6 --- /dev/null +++ b/pygmt/tests/baseline/test_plot3d_matrix_color.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 685f692faac5075282bc79a921a7a2f4 + size: 30476 + path: test_plot3d_matrix_color.png diff --git a/pygmt/tests/baseline/test_plot3d_projection.png.dvc b/pygmt/tests/baseline/test_plot3d_projection.png.dvc new file mode 100644 index 00000000000..1697b347edf --- /dev/null +++ b/pygmt/tests/baseline/test_plot3d_projection.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 945d98615aee38b41c7b86431af95875 + size: 29629 + path: test_plot3d_projection.png diff --git a/pygmt/tests/baseline/test_plot3d_red_circles_zscale.png.dvc b/pygmt/tests/baseline/test_plot3d_red_circles_zscale.png.dvc new file mode 100644 index 00000000000..2259ecf138d --- /dev/null +++ b/pygmt/tests/baseline/test_plot3d_red_circles_zscale.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 2919356bff9b9fbc47152f1f5df5817d + size: 34732 + path: test_plot3d_red_circles_zscale.png diff --git a/pygmt/tests/baseline/test_plot3d_red_circles_zsize.png.dvc b/pygmt/tests/baseline/test_plot3d_red_circles_zsize.png.dvc new file mode 100644 index 00000000000..4a29f7f8eae --- /dev/null +++ b/pygmt/tests/baseline/test_plot3d_red_circles_zsize.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 0fe9611ecaa271108eaaa49a82c63fb2 + size: 35405 + path: test_plot3d_red_circles_zsize.png diff --git a/pygmt/tests/baseline/test_plot3d_scalar_xyz.png.dvc b/pygmt/tests/baseline/test_plot3d_scalar_xyz.png.dvc new file mode 100644 index 00000000000..e600d4f7651 --- /dev/null +++ b/pygmt/tests/baseline/test_plot3d_scalar_xyz.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: b1df530f5916a91a6e7fb6ae1cdbf628 + size: 37030 + path: test_plot3d_scalar_xyz.png diff --git a/pygmt/tests/baseline/test_plot3d_sizes.png.dvc b/pygmt/tests/baseline/test_plot3d_sizes.png.dvc new file mode 100644 index 00000000000..4a37351c775 --- /dev/null +++ b/pygmt/tests/baseline/test_plot3d_sizes.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: b95bf07a96f69d1586fd548d2d22fa7c + size: 36565 + path: test_plot3d_sizes.png diff --git a/pygmt/tests/baseline/test_plot3d_sizes_colors_transparencies.png.dvc b/pygmt/tests/baseline/test_plot3d_sizes_colors_transparencies.png.dvc new file mode 100644 index 00000000000..5cb4c9331ad --- /dev/null +++ b/pygmt/tests/baseline/test_plot3d_sizes_colors_transparencies.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 064f6bd855691874b39c31c6b585e6ca + size: 30367 + path: test_plot3d_sizes_colors_transparencies.png diff --git a/pygmt/tests/baseline/test_plot3d_transparency.png.dvc b/pygmt/tests/baseline/test_plot3d_transparency.png.dvc new file mode 100644 index 00000000000..ba7ec2ca175 --- /dev/null +++ b/pygmt/tests/baseline/test_plot3d_transparency.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 399f9faeb033bf9e0e921bd2c571cc2d + size: 26077 + path: test_plot3d_transparency.png diff --git a/pygmt/tests/baseline/test_plot3d_varying_transparency.png.dvc b/pygmt/tests/baseline/test_plot3d_varying_transparency.png.dvc new file mode 100644 index 00000000000..0f63d669696 --- /dev/null +++ b/pygmt/tests/baseline/test_plot3d_varying_transparency.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 84693da1f92641eb3a1642eddd027d51 + size: 27634 + path: test_plot3d_varying_transparency.png diff --git a/pygmt/tests/baseline/test_plot3d_vectors.png.dvc b/pygmt/tests/baseline/test_plot3d_vectors.png.dvc new file mode 100644 index 00000000000..3914f3e9f6c --- /dev/null +++ b/pygmt/tests/baseline/test_plot3d_vectors.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: b3e3632a0a389576ba16a02ce115fb55 + size: 27387 + path: test_plot3d_vectors.png diff --git a/pygmt/tests/test_plot3d.py b/pygmt/tests/test_plot3d.py index 11ba0707897..492e95a9ca5 100644 --- a/pygmt/tests/test_plot3d.py +++ b/pygmt/tests/test_plot3d.py @@ -7,8 +7,6 @@ import pytest from pygmt import Figure from pygmt.exceptions import GMTInvalidInput -from pygmt.helpers import GMTTempFile -from pygmt.helpers.testing import check_figures_equal TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data") POINTS_DATA = os.path.join(TEST_DATA_DIR, "points.txt") @@ -30,62 +28,42 @@ def fixture_region(): return [10, 70, -5, 10, 0, 1] -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_plot3d_red_circles_zscale(data, region): "Plot the 3D data in red circles passing in vectors and setting zscale = 5" - fig_ref, fig_test = Figure(), Figure() - fig_ref.plot3d( - data=POINTS_DATA, - Jz=5, - p="225/30", - R="/".join(map(str, region)), - J="X4i", - S="c0.2c", - G="red", - B=["afg", "zafg"], - ) - fig_test.plot3d( + fig = Figure() + fig.plot3d( x=data[:, 0], y=data[:, 1], z=data[:, 2], zscale=5, perspective=[225, 30], region=region, - projection="X4i", + projection="X10c", style="c0.2c", color="red", frame=["afg", "zafg"], ) - return fig_ref, fig_test + return fig -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_plot3d_red_circles_zsize(data, region): - "Plot the 3D data in red circles passing in vectors and setting zsize = 3i" - fig_ref, fig_test = Figure(), Figure() - fig_ref.plot3d( - data=POINTS_DATA, - JZ="3i", - p="225/30", - R="/".join(map(str, region)), - J="X4i", - S="c0.2c", - G="red", - B=["afg", "zafg"], - ) - fig_test.plot3d( + "Plot the 3D data in red circles passing in vectors and setting zsize = 6c" + fig = Figure() + fig.plot3d( x=data[:, 0], y=data[:, 1], z=data[:, 2], - zsize="3i", + zsize="6c", perspective=[225, 30], region=region, - projection="X4i", + projection="X10c", style="c0.2c", color="red", frame=["afg", "zafg"], ) - return fig_ref, fig_test + return fig def test_plot3d_fail_no_data(data, region): @@ -95,13 +73,13 @@ def test_plot3d_fail_no_data(data, region): fig = Figure() with pytest.raises(GMTInvalidInput): fig.plot3d( - region=region, projection="X4i", style="c0.2c", color="red", frame="afg" + region=region, projection="X10c", style="c0.2c", color="red", frame="afg" ) with pytest.raises(GMTInvalidInput): fig.plot3d( x=data[:, 0], region=region, - projection="X4i", + projection="X10c", style="c0.2c", color="red", frame="afg", @@ -110,7 +88,7 @@ def test_plot3d_fail_no_data(data, region): fig.plot3d( y=data[:, 0], region=region, - projection="X4i", + projection="X10c", style="c0.2c", color="red", frame="afg", @@ -123,7 +101,7 @@ def test_plot3d_fail_no_data(data, region): z=data[:, 2], data=data, region=region, - projection="X4i", + projection="X10c", style="c0.2c", color="red", frame="afg", @@ -145,56 +123,34 @@ def test_plot3d_fail_color_size_intensity(data, region): fig.plot3d(style="cc", intensity=data[:, 2], color="red", **kwargs) -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_plot3d_projection(data, region): """ Plot the data in green squares with a projection. """ - fig_ref, fig_test = Figure(), Figure() - fig_ref.plot3d( - data=POINTS_DATA, - Jz=5, - p="225/30", - R="/".join(map(str, region)), - J="R270/4i", - S="s1c", - G="green", - B=["ag", "zag"], - ) - fig_test.plot3d( + fig = Figure() + fig.plot3d( x=data[:, 0], y=data[:, 1], z=data[:, 2], zscale=5, perspective=[225, 30], region=region, - projection="R270/4i", + projection="R270/10c", style="s1c", color="green", frame=["ag", "zag"], ) - return fig_ref, fig_test + return fig -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_plot3d_colors(data, region): """ Plot the data using z as colors. """ - fig_ref, fig_test = Figure(), Figure() - fig_ref.plot3d( - data=POINTS_DATA, - Jz=5, - p="225/30", - G="+z", - R="/".join(map(str, region)), - J="X3i", - S="c0.5c", - C="cubhelix", - B=["afg", "zafg"], - i="0,1,2,2", - ) - fig_test.plot3d( + fig = Figure() + fig.plot3d( x=data[:, 0], y=data[:, 1], z=data[:, 2], @@ -202,32 +158,21 @@ def test_plot3d_colors(data, region): perspective=[225, 30], color=data[:, 2], region=region, - projection="X3i", + projection="X6c", style="c0.5c", cmap="cubhelix", frame=["afg", "zafg"], ) - return fig_ref, fig_test + return fig -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_plot3d_sizes(data, region): """ Plot the data using z as sizes. """ - fig_ref, fig_test = Figure(), Figure() - fig_ref.plot3d( - data=POINTS_DATA, - Jz=5, - p="225/30", - i="0,1,2,2+s0.5", - R="/".join(map(str, region)), - J="X4i", - S="ui", - G="blue", - B=["af", "zaf"], - ) - fig_test.plot3d( + fig = Figure() + fig.plot3d( x=data[:, 0], y=data[:, 1], z=data[:, 2], @@ -235,34 +180,23 @@ def test_plot3d_sizes(data, region): perspective=[225, 30], sizes=0.5 * data[:, 2], region=region, - projection="X4i", + projection="X10c", # Using inches instead of cm because of upstream bug at # https://github.com/GenericMappingTools/gmt/issues/4386 style="ui", color="blue", frame=["af", "zaf"], ) - return fig_ref, fig_test + return fig -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_plot3d_colors_sizes(data, region): """ Plot the data using z as sizes and colors. """ - fig_ref, fig_test = Figure(), Figure() - fig_ref.plot3d( - data=POINTS_DATA, - Jz=5, - p="225/30", - i="0,1,2,2,2+s0.5", - R="/".join(map(str, region)), - J="X3i", - S="ui", - C="copper", - B=["af", "zaf"], - ) - fig_test.plot3d( + fig = Figure() + fig.plot3d( x=data[:, 0], y=data[:, 1], z=data[:, 2], @@ -271,42 +205,30 @@ def test_plot3d_colors_sizes(data, region): color=data[:, 2], sizes=0.5 * data[:, 2], region=region, - projection="X3i", + projection="X6c", # Using inches instead of cm because of upstream bug at # https://github.com/GenericMappingTools/gmt/issues/4386 style="ui", cmap="copper", frame=["af", "zaf"], ) - return fig_ref, fig_test + return fig -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_plot3d_colors_sizes_proj(data, region): """ Plot the data using z as sizes and colors with a projection. """ - fig_ref, fig_test = Figure(), Figure() - fig_ref.plot3d( - data=POINTS_DATA, - Jz=5, - p="225/30", - R="/".join(map(str, region)), - J="M10i", - B=["af", "zaf"], - G="+z", - i="0,1,2,2,2+s1", - S="ui", - C="copper", - ) - fig_test.plot3d( + fig = Figure() + fig.plot3d( x=data[:, 0], y=data[:, 1], z=data[:, 2], zscale=5, perspective=[225, 30], region=region, - projection="M10i", + projection="M20c", frame=["af", "zaf"], color=data[:, 2], sizes=data[:, 2], @@ -315,7 +237,7 @@ def test_plot3d_colors_sizes_proj(data, region): style="ui", cmap="copper", ) - return fig_ref, fig_test + return fig @pytest.mark.mpl_image_compare @@ -345,7 +267,7 @@ def test_plot3d_varying_intensity(): return fig -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_plot3d_transparency(): """ Plot the data with a constant transparency. @@ -354,39 +276,24 @@ def test_plot3d_transparency(): y = np.arange(1, 10) z = np.arange(1, 10) * 10 - fig_ref, fig_test = Figure(), Figure() - # Use single-character arguments for the reference image - with GMTTempFile() as tmpfile: - np.savetxt(tmpfile.name, np.c_[x, y, z], fmt="%d") - fig_ref.plot3d( - data=tmpfile.name, - S="u0.2c", - G="blue", - R="0/10/0/10/10/90", - J="X4i", - Jz=0.1, - B="", - p="135/30", - t=80.0, - ) - - fig_test.plot3d( + fig = Figure() + fig.plot3d( x=x, y=y, z=z, style="u0.2c", color="blue", region=[0, 10, 0, 10, 10, 90], - projection="X4i", + projection="X10c", zscale=0.1, frame=True, perspective=[135, 30], transparency=80.0, ) - return fig_ref, fig_test + return fig -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_plot3d_varying_transparency(): """ Plot the data using z as transparency using 3-D column symbols. @@ -395,38 +302,24 @@ def test_plot3d_varying_transparency(): y = np.arange(1, 10) z = np.arange(1, 10) * 10 - fig_ref, fig_test = Figure(), Figure() - # Use single-character arguments for the reference image - with GMTTempFile() as tmpfile: - np.savetxt(tmpfile.name, np.c_[x, y, z, z, z], fmt="%d") - fig_ref.plot3d( - data=tmpfile.name, - S="o0.2c+B5", - G="blue", - R="0/10/0/10/10/90", - J="X4i", - Jz=0.1, - B="", - p="135/30", - t="", - ) - fig_test.plot3d( + fig = Figure() + fig.plot3d( x=x, y=y, z=z, style="o0.2c+B5", color="blue", region=[0, 10, 0, 10, 10, 90], - projection="X4i", + projection="X10c", zscale=0.1, frame=True, perspective=[135, 30], transparency=z, ) - return fig_ref, fig_test + return fig -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_plot3d_sizes_colors_transparencies(): """ Plot the data with varying sizes and colors using z as transparency. @@ -438,27 +331,13 @@ def test_plot3d_sizes_colors_transparencies(): size = np.arange(1, 10) * 0.2 transparency = np.arange(1, 10) * 10 - fig_ref, fig_test = Figure(), Figure() - # Use single-character arguments for the reference image - with GMTTempFile() as tmpfile: - np.savetxt(tmpfile.name, np.c_[x, y, z, color, size, transparency]) - fig_ref.plot3d( - data=tmpfile.name, - R="0/10/0/10/10/90", - J="X4i", - Jz=0.1, - p="135/30", - B="", - S="uc", - C="gray", - t="", - ) - fig_test.plot3d( + fig = Figure() + fig.plot3d( x=x, y=y, z=z, region=[0, 10, 0, 10, 10, 90], - projection="X4i", + projection="X10c", zscale=0.1, perspective=[135, 30], frame=True, @@ -468,103 +347,70 @@ def test_plot3d_sizes_colors_transparencies(): cmap="gray", transparency=transparency, ) - return fig_ref, fig_test + return fig -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_plot3d_matrix(data, region): """ Plot the data passing in a matrix and specifying columns. """ - fig_ref, fig_test = Figure(), Figure() - fig_ref.plot3d( - data=POINTS_DATA, - Jz=5, - p="225/30", - R="/".join(map(str, region)), - J="M10i", - S="c1c", - G="#aaaaaa", - B=["a", "za"], - i="0,1,2", - ) - fig_test.plot3d( + fig = Figure() + fig.plot3d( data=data, zscale=5, perspective=[225, 30], region=region, - projection="M10i", + projection="M20c", style="c1c", color="#aaaaaa", frame=["a", "za"], columns="0,1,2", ) - return fig_ref, fig_test + return fig -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_plot3d_matrix_color(data, region): """ Plot the data passing in a matrix and using a colormap. """ - fig_ref, fig_test = Figure(), Figure() - fig_ref.plot3d( - data=POINTS_DATA, - Jz=5, - p="225/30", - R="/".join(map(str, region)), - J="X5i", - S="c0.5c", - C="rainbow", - i="0,1,2,2", - B=["a", "za"], - ) - fig_test.plot3d( + fig = Figure() + fig.plot3d( data=data, zscale=5, perspective=[225, 30], region=region, - projection="X5i", + projection="X10c", style="c0.5c", cmap="rainbow", columns=[0, 1, 2, 2], frame=["a", "za"], ) - return fig_ref, fig_test + return fig -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_plot3d_from_file(region): """ Plot using the data file name instead of loaded data. """ - fig_ref, fig_test = Figure(), Figure() - fig_ref.plot3d( - data=POINTS_DATA, - Jz=5, - p="225/30", - R="/".join(map(str, region)), - J="X10i", - S="d1c", - G="yellow", - B=["af", "zaf"], - i="0,1,2", - ) - fig_test.plot3d( + fig = Figure() + fig.plot3d( data=POINTS_DATA, zscale=5, perspective=[225, 30], region=region, - projection="X10i", + projection="X20c", style="d1c", color="yellow", frame=["af", "zaf"], columns=[0, 1, 2], ) - return fig_ref, fig_test + return fig -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_plot3d_vectors(): """ Plot vectors. @@ -574,20 +420,9 @@ def test_plot3d_vectors(): lon = np.sin(np.deg2rad(azimuth)) lat = np.cos(np.deg2rad(azimuth)) elev = np.tan(np.deg2rad(azimuth)) - fig_ref, fig_test = Figure(), Figure() - with GMTTempFile() as tmpfile: - np.savetxt(tmpfile.name, np.c_[lon, lat, elev, azimuth, lengths]) - fig_ref.plot3d( - data=tmpfile.name, - Jz=2, - p="225/30", - R="-2/2/-2/2/-2/2", - J="X4i", - S="V1c+e", - G="black", - B=["af", "zaf"], - ) - fig_test.plot3d( + + fig = Figure() + fig.plot3d( x=lon, y=lat, z=elev, @@ -595,42 +430,31 @@ def test_plot3d_vectors(): perspective=[225, 30], direction=(azimuth, lengths), region=[-2, 2, -2, 2, -2, 2], - projection="X4i", + projection="X10c", style="V1c+e", color="black", frame=["af", "zaf"], ) - return fig_ref, fig_test + return fig -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_plot3d_scalar_xyz(): """ Plot symbols given scalar x, y, z coordinates. """ - fig_ref, fig_test = Figure(), Figure() - with GMTTempFile() as tmpfile: - np.savetxt(tmpfile.name, np.c_[[-1.5, 0, 1.5], [1.5, 0, -1.5], [-1.5, 0, 1.5]]) - fig_ref.basemap( - R="-2/2/-2/2/-2/2", B=["xaf+lx", "yaf+ly", "zaf+lz"], Jz=2, p="225/30" - ) - fig_ref.plot3d(data=tmpfile.name, S="c1c", G="red", Jz="", p="", qi=0) - fig_ref.plot3d(data=tmpfile.name, S="t1c", G="green", Jz="", p="", qi=1) - fig_ref.plot3d(data=tmpfile.name, S="s1c", G="blue", Jz="", p="", qi=2) - - fig_test.basemap( + fig = Figure() + fig.basemap( region=[-2, 2, -2, 2, -2, 2], frame=["xaf+lx", "yaf+ly", "zaf+lz"], zscale=2, perspective=[225, 30], ) - fig_test.plot3d( + fig.plot3d( x=-1.5, y=1.5, z=-1.5, style="c1c", color="red", zscale=True, perspective=True ) - fig_test.plot3d( - x=0, y=0, z=0, style="t1c", color="green", zscale=True, perspective=True - ) - fig_test.plot3d( + fig.plot3d(x=0, y=0, z=0, style="t1c", color="green", zscale=True, perspective=True) + fig.plot3d( x=1.5, y=-1.5, z=1.5, style="s1c", color="blue", zscale=True, perspective=True ) - return fig_ref, fig_test + return fig