Skip to content

Commit 4f30a8f

Browse files
willschlitzerweiji14seisman
authored and
Josh Sixsmith
committed
Change test_makecpt.py to use colorbar instead of grdimage (GenericMappingTools#1748)
Co-authored-by: Wei Ji <[email protected]> Co-authored-by: Dongdong Tian <[email protected]>
1 parent 1829c82 commit 4f30a8f

12 files changed

+52
-61
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
outs:
2-
- md5: 9a8c5ecec5f8962987635057f577a01c
3-
size: 6029
2+
- md5: 49bc3322fbb073626fe5f61b92a473fb
3+
size: 4692
44
path: test_makecpt_categorical.png
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
outs:
2-
- md5: 9a18c81caa92725aa9de5c2dd7d74e46
3-
size: 75856
2+
- md5: 28eec5c7c5b76ba0659c20dd60ed8108
3+
size: 2861
44
path: test_makecpt_continuous.png
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
outs:
2-
- md5: 4ad410eb2843b3b47818121563c79254
3-
size: 4628
2+
- md5: 150c12b8d8959561bdf36d380dc23d10
3+
size: 3747
44
path: test_makecpt_cyclic.png
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
outs:
2+
- md5: 989d9bf57f716f4721f14992bf39a359
3+
size: 2529
4+
path: test_makecpt_plot_colorbar.png
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
outs:
2+
- md5: dbf2dcd2c30bdb921599a09b0ba258f8
3+
size: 3386
4+
path: test_makecpt_plot_colorbar_scaled_with_series.png

pygmt/tests/baseline/test_makecpt_plot_grid.png.dvc

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

pygmt/tests/baseline/test_makecpt_plot_grid_scaled_with_series.png.dvc

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
outs:
2-
- md5: b28ff0dad316d0b6a860b8af7e402a56
2+
- md5: 7944289487b6efd9755a931e371d8022
33
size: 26601
44
path: test_makecpt_plot_points.png
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
outs:
2-
- md5: 6a5ca01aebcc23b00dc884fcd9c927d8
3-
size: 141567
2+
- md5: 412c8de63e53ebac483e0fd42b79cad6
3+
size: 3620
44
path: test_makecpt_reverse_color_and_zsign.png
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
outs:
2-
- md5: 5ad9b6aab72e45be8a1adc20f9e1c0e9
3-
size: 71377
2+
- md5: 3d919f2db5ae1302f38a0178224074c6
3+
size: 3964
44
path: test_makecpt_reverse_color_only.png
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
outs:
2-
- md5: 26f3d0d95a68799ddd4eb8a130bc1445
3-
size: 97790
2+
- md5: 8235d66d1606fce2380f7fd034e874c1
3+
size: 2907
44
path: test_makecpt_truncated_zlow_zhigh.png

pygmt/tests/test_makecpt.py

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import numpy as np
77
import pytest
88
from pygmt import Figure, makecpt
9-
from pygmt.datasets import load_earth_relief
109
from pygmt.exceptions import GMTInvalidInput
1110
from pygmt.helpers import GMTTempFile
1211

@@ -22,24 +21,16 @@ def fixture_points():
2221
return np.loadtxt(POINTS_DATA)
2322

2423

25-
@pytest.fixture(scope="module", name="region")
26-
def fixture_region():
24+
@pytest.fixture(scope="module", name="position")
25+
def fixture_position():
2726
"""
28-
The data region.
27+
Return a standard position argument for the colorbar.
2928
"""
30-
return [10, 70, -5, 10]
31-
32-
33-
@pytest.fixture(scope="module", name="grid")
34-
def fixture_grid():
35-
"""
36-
Load the grid data from the sample earth_relief file.
37-
"""
38-
return load_earth_relief(registration="gridline")
29+
return "x0c/0c+w10c+h"
3930

4031

4132
@pytest.mark.mpl_image_compare
42-
def test_makecpt_plot_points(points, region):
33+
def test_makecpt_plot_points(points):
4334
"""
4435
Use static color palette table to change color of points.
4536
"""
@@ -49,33 +40,33 @@ def test_makecpt_plot_points(points, region):
4940
x=points[:, 0],
5041
y=points[:, 1],
5142
color=points[:, 2],
52-
region=region,
43+
region=[10, 70, -5, 10],
5344
style="c1c",
5445
cmap=True,
5546
)
5647
return fig
5748

5849

5950
@pytest.mark.mpl_image_compare
60-
def test_makecpt_plot_grid(grid):
51+
def test_makecpt_plot_colorbar(position):
6152
"""
62-
Use static color palette table to change color of grid.
53+
Use static color palette table to plot a colorbar.
6354
"""
6455
fig = Figure()
6556
makecpt(cmap="relief")
66-
fig.grdimage(grid, projection="W0/10c")
57+
fig.colorbar(cmap=True, frame=True, position=position)
6758
return fig
6859

6960

7061
@pytest.mark.mpl_image_compare
71-
def test_makecpt_plot_grid_scaled_with_series(grid):
62+
def test_makecpt_plot_colorbar_scaled_with_series(position):
7263
"""
73-
Use static color palette table scaled to a min/max series to change color
74-
of grid.
64+
Use static color palette table scaled to a min/max series and plot it on a
65+
colorbar.
7566
"""
7667
fig = Figure()
77-
makecpt(cmap="oleron", series=[-4500, 4500])
78-
fig.grdimage(grid, projection="W0/10c")
68+
makecpt(cmap="oleron", series=[0, 1000])
69+
fig.colorbar(cmap=True, frame=True, position=position)
7970
return fig
8071

8172

@@ -105,70 +96,70 @@ def test_makecpt_invalid_output():
10596

10697

10798
@pytest.mark.mpl_image_compare
108-
def test_makecpt_truncated_zlow_zhigh(grid):
99+
def test_makecpt_truncated_zlow_zhigh(position):
109100
"""
110101
Use static color palette table that is truncated to z-low and z-high.
111102
"""
112103
fig = Figure()
113-
makecpt(cmap="rainbow", truncate=[0.15, 0.85], series=[-4500, 4500])
114-
fig.grdimage(grid, projection="W0/10c")
104+
makecpt(cmap="rainbow", truncate=[0.15, 0.85], series=[0, 1000])
105+
fig.colorbar(cmap=True, frame=True, position=position)
115106
return fig
116107

117108

118109
@pytest.mark.mpl_image_compare
119-
def test_makecpt_reverse_color_only(grid):
110+
def test_makecpt_reverse_color_only(position):
120111
"""
121112
Use static color palette table with its colors reversed.
122113
"""
123114
fig = Figure()
124-
makecpt(cmap="earth", reverse=True)
125-
fig.grdimage(grid, projection="W0/10c")
115+
makecpt(cmap="earth", reverse=True, series=[0, 1000])
116+
fig.colorbar(cmap=True, frame=True, position=position)
126117
return fig
127118

128119

129120
@pytest.mark.mpl_image_compare
130-
def test_makecpt_reverse_color_and_zsign(grid):
121+
def test_makecpt_reverse_color_and_zsign(position):
131122
"""
132123
Use static color palette table with both its colors and z-value sign
133124
reversed.
134125
"""
135126
fig = Figure()
136-
makecpt(cmap="earth", reverse="cz")
137-
fig.grdimage(grid, projection="W0/10c")
127+
makecpt(cmap="earth", reverse="cz", series=[0, 1000])
128+
fig.colorbar(cmap=True, frame=True, position=position)
138129
return fig
139130

140131

141132
@pytest.mark.mpl_image_compare
142-
def test_makecpt_continuous(grid):
133+
def test_makecpt_continuous(position):
143134
"""
144135
Use static color palette table that is continuous from blue to white and
145-
scaled from -4500 to 4500m.
136+
scaled from 0 to 1000 m.
146137
"""
147138
fig = Figure()
148-
makecpt(cmap="blue,white", continuous=True, series=[-4500, 4500])
149-
fig.grdimage(grid, projection="W0/10c")
139+
makecpt(cmap="blue,white", continuous=True, series=[0, 1000])
140+
fig.colorbar(cmap=True, frame=True, position=position)
150141
return fig
151142

152143

153144
@pytest.mark.mpl_image_compare
154-
def test_makecpt_categorical(region):
145+
def test_makecpt_categorical(position):
155146
"""
156147
Use static color palette table that is categorical.
157148
"""
158149
fig = Figure()
159150
makecpt(cmap="categorical", categorical=True)
160-
fig.colorbar(cmap=True, region=region, frame=True, position="JBC")
151+
fig.colorbar(cmap=True, frame=True, position=position)
161152
return fig
162153

163154

164155
@pytest.mark.mpl_image_compare
165-
def test_makecpt_cyclic(region):
156+
def test_makecpt_cyclic(position):
166157
"""
167158
Use static color palette table that is cyclic.
168159
"""
169160
fig = Figure()
170161
makecpt(cmap="cork", cyclic=True)
171-
fig.colorbar(cmap=True, region=region, frame=True, position="JBC")
162+
fig.colorbar(cmap=True, frame=True, position=position)
172163
return fig
173164

174165

0 commit comments

Comments
 (0)