|
5 | 5 | import os
|
6 | 6 |
|
7 | 7 | import pytest
|
| 8 | +import numpy as np |
8 | 9 |
|
9 | 10 | from .. import Figure
|
10 | 11 | from ..exceptions import GMTCLibError, GMTInvalidInput
|
11 | 12 | from ..helpers import GMTTempFile
|
| 13 | +from ..helpers.testing import check_figures_equal |
12 | 14 |
|
13 | 15 | TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
|
14 | 16 | POINTS_DATA = os.path.join(TEST_DATA_DIR, "points.txt")
|
@@ -295,3 +297,44 @@ def test_text_angle_font_justify_from_textfile():
|
295 | 297 | justify=True,
|
296 | 298 | )
|
297 | 299 | return fig
|
| 300 | + |
| 301 | + |
| 302 | +@check_figures_equal() |
| 303 | +def test_text_transparency(): |
| 304 | + "Add texts with a constant transparency" |
| 305 | + x = np.arange(1, 10) |
| 306 | + y = np.arange(11, 20) |
| 307 | + text = [f"TEXT-{i}-{j}" for i, j in zip(x, y)] |
| 308 | + |
| 309 | + fig_ref, fig_test = Figure(), Figure() |
| 310 | + # Use single-character arguments for the reference image |
| 311 | + with GMTTempFile() as tmpfile: |
| 312 | + np.savetxt(tmpfile.name, np.c_[x, y, text], fmt="%s") |
| 313 | + fig_ref.basemap(R="0/10/10/20", J="X10c", B="") |
| 314 | + fig_ref.text(textfiles=tmpfile.name, t=50) |
| 315 | + |
| 316 | + fig_test.basemap(region=[0, 10, 10, 20], projection="X10c", frame=True) |
| 317 | + fig_test.text(x=x, y=y, text=text, transparency=50) |
| 318 | + |
| 319 | + return fig_ref, fig_test |
| 320 | + |
| 321 | + |
| 322 | +@check_figures_equal() |
| 323 | +def test_text_varying_transparency(): |
| 324 | + "Add texts with varying transparency" |
| 325 | + x = np.arange(1, 10) |
| 326 | + y = np.arange(11, 20) |
| 327 | + text = [f"TEXT-{i}-{j}" for i, j in zip(x, y)] |
| 328 | + transparency = np.arange(10, 100, 10) |
| 329 | + |
| 330 | + fig_ref, fig_test = Figure(), Figure() |
| 331 | + # Use single-character arguments for the reference image |
| 332 | + with GMTTempFile() as tmpfile: |
| 333 | + np.savetxt(tmpfile.name, np.c_[x, y, transparency, text], fmt="%s") |
| 334 | + fig_ref.basemap(R="0/10/10/20", J="X10c", B="") |
| 335 | + fig_ref.text(textfiles=tmpfile.name, t="") |
| 336 | + |
| 337 | + fig_test.basemap(region=[0, 10, 10, 20], projection="X10c", frame=True) |
| 338 | + fig_test.text(x=x, y=y, text=text, transparency=transparency) |
| 339 | + |
| 340 | + return fig_ref, fig_test |
0 commit comments