Repository: GenericMappingTools/pygmt

Issue:
fig.text() doesn't work if "text" is integer or float
**Description of the problem**

<!-- Please be as detailed as you can when describing an issue. The more information we have, the easier it will be for us to track this down. -->

**Full code that generated the error**

```python
import pygmt
fig = pygmt.Figure()
fig.basemap(region=[0, 10, 0, 10], projection="X10c/10c", frame=True)
fig.text(x=5, y=5, text=5)
fig.show()
```

**Full error message**

```
text [ERROR]: Text record line 0 is NULL! Skipped but this is trouble)
```

It works before, but fails in recent releases.

**System information**

Please paste the output of `python -c "import pygmt; pygmt.show_versions()"`:

```
PyGMT information:
  version: v0.2.2.dev9+g0cb8b609
System information:
  python: 3.8.3 (default, Jul  2 2020, 11:26:31)  [Clang 10.0.0 ]
  executable: /Users/seisman/.anaconda/bin/python
  machine: macOS-10.15.7-x86_64-i386-64bit
Dependency information:
  numpy: 1.19.2
  pandas: 1.1.4
  xarray: 0.16.1
  netCDF4: 1.5.4
  packaging: 20.4
  ghostscript: 9.53.3
  gmt: 6.2.0_d266c30_2020.11.25
GMT library information:
  binary dir: /Users/seisman/.anaconda/bin
  cores: 8
  grid layout: rows
  library path: /Users/seisman/local/GMT/lib/libgmt.dylib
  padding: 2
  plugin dir: /Users/seisman/local/GMT/lib/gmt/plugins
  share dir: /Users/seisman/local/GMT/share
  version: 6.2.0
```

Discussion:

Patch:
diff --git a/pygmt/base_plotting.py b/pygmt/base_plotting.py
index a203def4..5b1f4076 100644
--- a/pygmt/base_plotting.py
+++ b/pygmt/base_plotting.py
@@ -1536,7 +1536,8 @@ class BasePlotting:
                         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)])


Test patch:
diff --git a/pygmt/tests/test_text.py b/pygmt/tests/test_text.py
index e267a8bf..e23a0489 100644
--- a/pygmt/tests/test_text.py
+++ b/pygmt/tests/test_text.py
@@ -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