6
6
import numpy as np
7
7
import pytest
8
8
from pygmt import Figure , makecpt
9
- from pygmt .datasets import load_earth_relief
10
9
from pygmt .exceptions import GMTInvalidInput
11
10
from pygmt .helpers import GMTTempFile
12
11
@@ -22,24 +21,16 @@ def fixture_points():
22
21
return np .loadtxt (POINTS_DATA )
23
22
24
23
25
- @pytest .fixture (scope = "module" , name = "region " )
26
- def fixture_region ():
24
+ @pytest .fixture (scope = "module" , name = "position " )
25
+ def fixture_position ():
27
26
"""
28
- The data region .
27
+ Return a standard position argument for the colorbar .
29
28
"""
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"
39
30
40
31
41
32
@pytest .mark .mpl_image_compare
42
- def test_makecpt_plot_points (points , region ):
33
+ def test_makecpt_plot_points (points ):
43
34
"""
44
35
Use static color palette table to change color of points.
45
36
"""
@@ -49,33 +40,33 @@ def test_makecpt_plot_points(points, region):
49
40
x = points [:, 0 ],
50
41
y = points [:, 1 ],
51
42
color = points [:, 2 ],
52
- region = region ,
43
+ region = [ 10 , 70 , - 5 , 10 ] ,
53
44
style = "c1c" ,
54
45
cmap = True ,
55
46
)
56
47
return fig
57
48
58
49
59
50
@pytest .mark .mpl_image_compare
60
- def test_makecpt_plot_grid ( grid ):
51
+ def test_makecpt_plot_colorbar ( position ):
61
52
"""
62
- Use static color palette table to change color of grid .
53
+ Use static color palette table to plot a colorbar .
63
54
"""
64
55
fig = Figure ()
65
56
makecpt (cmap = "relief" )
66
- fig .grdimage ( grid , projection = "W0/10c" )
57
+ fig .colorbar ( cmap = True , frame = True , position = position )
67
58
return fig
68
59
69
60
70
61
@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 ):
72
63
"""
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 .
75
66
"""
76
67
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 )
79
70
return fig
80
71
81
72
@@ -105,70 +96,70 @@ def test_makecpt_invalid_output():
105
96
106
97
107
98
@pytest .mark .mpl_image_compare
108
- def test_makecpt_truncated_zlow_zhigh (grid ):
99
+ def test_makecpt_truncated_zlow_zhigh (position ):
109
100
"""
110
101
Use static color palette table that is truncated to z-low and z-high.
111
102
"""
112
103
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 )
115
106
return fig
116
107
117
108
118
109
@pytest .mark .mpl_image_compare
119
- def test_makecpt_reverse_color_only (grid ):
110
+ def test_makecpt_reverse_color_only (position ):
120
111
"""
121
112
Use static color palette table with its colors reversed.
122
113
"""
123
114
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 )
126
117
return fig
127
118
128
119
129
120
@pytest .mark .mpl_image_compare
130
- def test_makecpt_reverse_color_and_zsign (grid ):
121
+ def test_makecpt_reverse_color_and_zsign (position ):
131
122
"""
132
123
Use static color palette table with both its colors and z-value sign
133
124
reversed.
134
125
"""
135
126
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 )
138
129
return fig
139
130
140
131
141
132
@pytest .mark .mpl_image_compare
142
- def test_makecpt_continuous (grid ):
133
+ def test_makecpt_continuous (position ):
143
134
"""
144
135
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 .
146
137
"""
147
138
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 )
150
141
return fig
151
142
152
143
153
144
@pytest .mark .mpl_image_compare
154
- def test_makecpt_categorical (region ):
145
+ def test_makecpt_categorical (position ):
155
146
"""
156
147
Use static color palette table that is categorical.
157
148
"""
158
149
fig = Figure ()
159
150
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 )
161
152
return fig
162
153
163
154
164
155
@pytest .mark .mpl_image_compare
165
- def test_makecpt_cyclic (region ):
156
+ def test_makecpt_cyclic (position ):
166
157
"""
167
158
Use static color palette table that is cyclic.
168
159
"""
169
160
fig = Figure ()
170
161
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 )
172
163
return fig
173
164
174
165
0 commit comments