|
13 | 13 |
|
14 | 14 | from .. import Figure
|
15 | 15 | from ..exceptions import GMTInvalidInput
|
| 16 | +from ..helpers import GMTTempFile |
| 17 | +from ..helpers.testing import check_figures_equal |
16 | 18 |
|
17 | 19 |
|
18 | 20 | TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
|
@@ -128,7 +130,7 @@ def test_plot_projection(data):
|
128 | 130 |
|
129 | 131 | @pytest.mark.mpl_image_compare
|
130 | 132 | def test_plot_colors(data, region):
|
131 |
| - "Plot the data using z as sizes" |
| 133 | + "Plot the data using z as colors" |
132 | 134 | fig = Figure()
|
133 | 135 | fig.plot(
|
134 | 136 | x=data[:, 0],
|
@@ -194,6 +196,104 @@ def test_plot_colors_sizes_proj(data, region):
|
194 | 196 | return fig
|
195 | 197 |
|
196 | 198 |
|
| 199 | +@check_figures_equal() |
| 200 | +def test_plot_transparency(): |
| 201 | + "Plot the data with a constant transparency" |
| 202 | + x = np.arange(1, 10) |
| 203 | + y = np.arange(1, 10) |
| 204 | + |
| 205 | + fig_ref, fig_test = Figure(), Figure() |
| 206 | + # Use single-character arguments for the reference image |
| 207 | + with GMTTempFile() as tmpfile: |
| 208 | + np.savetxt(tmpfile.name, np.c_[x, y], fmt="%d") |
| 209 | + fig_ref.plot( |
| 210 | + data=tmpfile.name, S="c0.2c", G="blue", t=80.0, R="0/10/0/10", J="X4i", B="" |
| 211 | + ) |
| 212 | + |
| 213 | + fig_test.plot( |
| 214 | + x=x, |
| 215 | + y=y, |
| 216 | + region=[0, 10, 0, 10], |
| 217 | + projection="X4i", |
| 218 | + frame=True, |
| 219 | + style="c0.2c", |
| 220 | + color="blue", |
| 221 | + transparency=80.0, |
| 222 | + ) |
| 223 | + return fig_ref, fig_test |
| 224 | + |
| 225 | + |
| 226 | +@check_figures_equal() |
| 227 | +def test_plot_varying_transparency(): |
| 228 | + "Plot the data using z as transparency" |
| 229 | + x = np.arange(1, 10) |
| 230 | + y = np.arange(1, 10) |
| 231 | + z = np.arange(1, 10) * 10 |
| 232 | + |
| 233 | + fig_ref, fig_test = Figure(), Figure() |
| 234 | + # Use single-character arguments for the reference image |
| 235 | + with GMTTempFile() as tmpfile: |
| 236 | + np.savetxt(tmpfile.name, np.c_[x, y, z], fmt="%d") |
| 237 | + fig_ref.plot( |
| 238 | + data=tmpfile.name, |
| 239 | + R="0/10/0/10", |
| 240 | + J="X4i", |
| 241 | + B="", |
| 242 | + S="c0.2c", |
| 243 | + G="blue", |
| 244 | + t="", |
| 245 | + ) |
| 246 | + |
| 247 | + fig_test.plot( |
| 248 | + x=x, |
| 249 | + y=y, |
| 250 | + region=[0, 10, 0, 10], |
| 251 | + projection="X4i", |
| 252 | + frame=True, |
| 253 | + style="c0.2c", |
| 254 | + color="blue", |
| 255 | + transparency=z, |
| 256 | + ) |
| 257 | + return fig_ref, fig_test |
| 258 | + |
| 259 | + |
| 260 | +@check_figures_equal() |
| 261 | +def test_plot_sizes_colors_transparencies(): |
| 262 | + "Plot the data using z as transparency" |
| 263 | + x = np.arange(1.0, 10.0) |
| 264 | + y = np.arange(1.0, 10.0) |
| 265 | + color = np.arange(1, 10) * 0.15 |
| 266 | + size = np.arange(1, 10) * 0.2 |
| 267 | + transparency = np.arange(1, 10) * 10 |
| 268 | + |
| 269 | + fig_ref, fig_test = Figure(), Figure() |
| 270 | + # Use single-character arguments for the reference image |
| 271 | + with GMTTempFile() as tmpfile: |
| 272 | + np.savetxt(tmpfile.name, np.c_[x, y, color, size, transparency]) |
| 273 | + fig_ref.plot( |
| 274 | + data=tmpfile.name, |
| 275 | + R="0/10/0/10", |
| 276 | + J="X4i", |
| 277 | + B="", |
| 278 | + S="cc", |
| 279 | + C="gray", |
| 280 | + t="", |
| 281 | + ) |
| 282 | + fig_test.plot( |
| 283 | + x=x, |
| 284 | + y=y, |
| 285 | + region=[0, 10, 0, 10], |
| 286 | + projection="X4i", |
| 287 | + frame=True, |
| 288 | + style="cc", |
| 289 | + color=color, |
| 290 | + sizes=size, |
| 291 | + cmap="gray", |
| 292 | + transparency=transparency, |
| 293 | + ) |
| 294 | + return fig_ref, fig_test |
| 295 | + |
| 296 | + |
197 | 297 | @pytest.mark.mpl_image_compare
|
198 | 298 | def test_plot_matrix(data):
|
199 | 299 | "Plot the data passing in a matrix and specifying columns"
|
|
0 commit comments