GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
758 stars 220 forks source link

Figure.text sometimes doesn't work if the text contains single/double quotation marks #3104

Closed xumi1993 closed 6 months ago

xumi1993 commented 8 months ago

Description of the problem

I want to write text of A' on a figure with text box filled by a colour of fill='230'. When I use position='CM' to specify the position of the text, the A' -G230 is shown in the figure. I think the attribute fill='230' have not been correctly parsed. ff6b8c3c-060b-4295-977a-684e0051dcd6

Minimal Complete Verifiable Example

label = "A\'"
fig = pygmt.Figure()
fig.basemap(region=[0, 10, 0, 10], projection="X4c/4c", frame=True)
fig.text(
    text=label,
    position='CM',
    fill='230'    
)
fig.show()

Full error message

No response

System information

PyGMT information:
  version: v0.11.0
System information:
  python: 3.9.13 | packaged by conda-forge | (main, May 27 2022, 17:00:33)  [Clang 13.0.1 ]
  executable: /Users/xumijian/miniconda3_arm/bin/python
  machine: macOS-14.2.1-arm64-arm-64bit
Dependency information:
  numpy: 1.24.2
  pandas: 2.2.1
  xarray: 2023.5.0
  netCDF4: 1.6.0
  packaging: 24.0
  contextily: None
  geopandas: None
  ipython: None
  rioxarray: None
  ghostscript: 10.02.1
GMT library information:
  cores: 10
  grid layout: rows
  image layout: 
  library path: /Users/xumijian/miniconda3_arm/lib/libgmt.dylib
  padding: 2
  plugin dir: /Users/xumijian/miniconda3_arm/lib/gmt/plugins
  share dir: /Users/xumijian/miniconda3_arm/share/gmt
  version: 6.3.0
seisman commented 8 months ago

I can reproduce the issue. It's the single quote ' that causes the trouble. A temporary workaround is using

label = "A\\047"
xumi1993 commented 8 months ago

Thanks you very much for the temporary solution. Looking forward to the next version solving this issue.

seisman commented 8 months ago

PR #3105 should fix the issue.

Edit: wait. PR #3105 causes more troubles.