-
Notifications
You must be signed in to change notification settings - Fork 248
Figure.text: Support non-ASCII characters in the 'text' parameter #2638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
547f51b
d823169
30ae4c1
73b919f
85a0926
adf6eda
05f2299
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,4 +19,5 @@ | |
| data_kind, | ||
| is_nonstr_iter, | ||
| launch_external_viewer, | ||
| non_ascii_to_octal, | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| fmt_docstring, | ||
| is_nonstr_iter, | ||
| kwargs_to_strings, | ||
| non_ascii_to_octal, | ||
| use_alias, | ||
| ) | ||
|
|
||
|
|
@@ -65,6 +66,12 @@ def text_( | |
| - ``x``/``y``, and ``text`` | ||
| - ``position`` and ``text`` | ||
|
|
||
| The text strings passed via the ``text`` parameter can contain ASCII | ||
| characters and non-ASCII characters defined in the ISOLatin1+ encoding | ||
| (i.e., IEC_8859-1), and the Symbol and ZapfDingbats character sets. | ||
| Ses :gmt-docs:`cookbook/octal-codes.html` for the full list of supported | ||
| non-ASCII characters. | ||
|
|
||
| Full option list at :gmt-docs:`text.html` | ||
|
|
||
| {aliases} | ||
|
|
@@ -223,7 +230,9 @@ def text_( | |
|
|
||
| # Append text at last column. Text must be passed in as str type. | ||
| if kind == "vectors": | ||
| extra_arrays.append(np.atleast_1d(text).astype(str)) | ||
| extra_arrays.append( | ||
| list(map(non_ascii_to_octal, np.atleast_1d(text).astype(str))) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be a list of numpy arrays, instead of being just a numpy array? Is there a way to keep it as a numpy array?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to |
||
| ) | ||
|
|
||
| with Session() as lib: | ||
| file_context = lib.virtualfile_from_data( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| outs: | ||
| - md5: 75db22909db0fbdb2a31edab357ed8b9 | ||
| size: 16418 | ||
| hash: md5 | ||
| path: test_text_nonascii.png |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -371,3 +371,16 @@ def test_text_nonstr_text(): | |
| text=[1, 2, 3.0, 4.0], | ||
| ) | ||
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_text_nonascii(): | ||
| """ | ||
| Test passing text strings with non-ascii characters. | ||
| """ | ||
| fig = Figure() | ||
| fig.basemap(region=[0, 10, 0, 10], projection="X10c", frame=True) | ||
| fig.text(position="TL", text="position-text:°α") | ||
| fig.text(x=1, y=1, text="xytext:°α") | ||
| fig.text(x=[5, 5], y=[3, 5], text=["xytext1:°α", "xytext2:°α"]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mix in some Symbol and ZapfDingbats characters too from https://docs.generic-mapping-tools.org/latest/cookbook/octal-codes.html#octal-codes-symbol-zap?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in adf6eda. |
||
| return fig | ||
Uh oh!
There was an error while loading. Please reload this page.