Skip to content

Commit

Permalink
Fix the bug for Figure.text() when "text" is a non-string array (#724)
Browse files Browse the repository at this point in the history
In `Figure.text()`, the `text` array must be in string type.

Closes #706.
  • Loading branch information
seisman authored Dec 11, 2020
1 parent 2a88f73 commit 2128dd4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pygmt/base_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,8 @@ def text(
np.atleast_1d(x),
np.atleast_1d(y),
*extra_arrays,
np.atleast_1d(text),
# text must be in str type, see issue #706
np.atleast_1d(text).astype(str),
)
with file_context as fname:
arg_str = " ".join([fname, build_arg_string(kwargs)])
Expand Down
23 changes: 23 additions & 0 deletions pygmt/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,26 @@ def test_text_varying_transparency():
fig_test.text(x=x, y=y, text=text, transparency=transparency)

return fig_ref, fig_test


@check_figures_equal()
def test_text_nonstr_text():
"Input text is in non-string type (e.g., int, float)"
fig_ref, fig_test = Figure(), Figure()

# Use single-character arguments and input files for the reference image
with GMTTempFile(suffix=".txt") as tempfile:
with open(tempfile.name, "w") as tmpfile:
tmpfile.write("1 1 1.0\n2 2 2.0\n3 3 3.0\n4 4 4.0\n")
fig_ref.text(R="0/10/0/10", J="X10c", B="", textfiles=tempfile.name)

fig_test.text(
region=[0, 10, 0, 10],
projection="X10c",
frame=True,
x=[1, 2, 3, 4],
y=[1, 2, 3, 4],
text=[1, 2, 3.0, 4.0],
)

return fig_ref, fig_test

0 comments on commit 2128dd4

Please sign in to comment.