Skip to content

changing map annotation font size #733

Open

Description

@uliw

Description of the problem

Setting

pygmt.config(FONT_ANNOT="6p")

appears to have no effect and setting it directly like this

fig.basemap(
    region=region,
    projection=projection,
    frame=True,
    font_annot="6p")

results in a parsing error.

GMTCLibError: Module 'basemap' failed with status code 71:
basemap [ERROR]: Malformed -f argument [ont_annot6p]
basemap [ERROR]: Option -f parsing failure. Correct syntax:
basemap [ERROR]: Offending option -font_annot6p

I may not see the forest for trees here... so any pointers are much appreciated

PyGMT information:
  version: v0.2.1
System information:
  python: 3.8.6 | packaged by conda-forge | (default, Oct  7 2020, 19:08:05)  [GCC 7.5.0]
  executable: /home/uliw/anaconda3/bin/python
  machine: Linux-5.9.1-2-default-x86_64-with-glibc2.10
Dependency information:
  numpy: 1.18.5
  pandas: 1.1.5
  xarray: 0.16.2
  netCDF4: 1.5.5
  packaging: 20.8
  ghostscript: 9.53.3
  gmt: 6.1.1
GMT library information:
  binary dir: /home/uliw/anaconda3/bin
  cores: 8
  grid layout: rows
  library path: /home/uliw/anaconda3/lib/libgmt.so
  padding: 2
  plugin dir: /home/uliw/anaconda3/lib/gmt/plugins
  share dir: /home/uliw/anaconda3/share/gmt
  version: 6.1.1

This is

Full code that generated the error

PASTE CODE HERE

Full error message

PASTE ERROR MESSAGE HERE

System information

Please paste the output of python -c "import pygmt; pygmt.show_versions()":

PASTE THE OUTPUT HERE

Activity

  1. seisman commented on Dec 14, 2020

    @seisman
    Member

    Setting pygmt.config(FONT_ANNOT="6p") should work. Could you please provide your full codes?

  2. uliw commented on Dec 14, 2020

    @uliw
    Author

    Here is an example. Changing the value from 6 to e.g., does not affect the font size

    import pygmt
    
    pygmt.config(FONT_ANNOT="6p")
    
    projection = "A-95/42/4i" 
    region = "-119/22/-50/50r" 
    fig = pygmt.Figure()
    fig.basemap(
        region=region,
        projection=projection,
        frame=True,
    )
    fig.show()
    
  3. seisman commented on Dec 14, 2020

    @seisman
    Member

    OK. I can reproduce your issue. Will see why it doesn't work as expected.

    Here is a workaround:

    import pygmt
    
    projection = "A-95/42/4i" 
    region = "-119/22/-50/50r" 
    fig = pygmt.Figure()
    
    pygmt.config(FONT_ANNOT="6p")
    
    fig.basemap(
        region=region,
        projection=projection,
        frame=True,
    )
    fig.show()
    
  4. added
    bug
    on Dec 14, 2020
  5. uliw commented on Dec 14, 2020

    @uliw
    Author
  6. seisman commented on Dec 14, 2020

    @seisman
    Member

    Here is the step to reproduce the issue and understand why it doesn't work as expected.

    We first need to start a jupyter notebook, and run the following script.

    import pygmt
    
    pygmt.config(FONT_ANNOT="20p")
    
    projection = "A-95/42/4i" 
    region = "-119/22/-50/50r" 
    fig = pygmt.Figure()
    fig.basemap(
        region=region,
        projection=projection,
        frame=True,
    )
    fig.show()

    import pygmt creates a new session, and pygmt.config() changes GMT's global settings. The script can produce a plot with a large annotation font size, as expected.

    Then, in the same jupyter notebook, we can change the annotation font size 20p to 6p, and run the script again. It still produces a plot with a large annotation font size.

    We can rewrite the above processes into a single script, like below:

    # "import pygmt" start a new session
    import pygmt
    
    # it changes GMT's global settings
    pygmt.config(FONT_ANNOT="20p")
    
    projection = "A-95/42/4i" 
    region = "-119/22/-50/50r" 
    fig = pygmt.Figure()
    # the basemap has an annotation font size of 20p, as determined by the global FONT_ANNOT setting
    fig.basemap(
        region=region,
        projection=projection,
        frame=True,
    )
    fig.show()
    
    # here, "import pygmt" doesn't start a new session
    import pygmt
    
    # here, "pygmt.config()" changes the **local** settings of the **previous** figure, so it doesn't affect the next figure
    pygmt.config(FONT_ANNOT="6p")
    
    projection = "A-95/42/4i" 
    region = "-119/22/-50/50r" 
    fig = pygmt.Figure()
    # the basemap still has an annotation font size of 20p, as determined by the global FONT_ANNOT setting
    fig.basemap(
        region=region,
        projection=projection,
        frame=True,
    )
    fig.show()
  7. weiji14 commented on Feb 17, 2021

    @weiji14
    Member

    My reading of this issue is that it is a problem related to having one GMT session open all the time in PyGMT (c.f. #867). Either we:

    1. create a fig.destroy()/fig.clear() (or similar) method
    2. have a context manager like with pygmt.Figure() as fig: fig.* ... to keep the scope of things local.
    3. we enforce/strongly recommend the use of pygmt.config in a with statement so that things are kept to a local scope only.

    This is needed to ensure that one figure session doesn't pollute the configurations of subsequent figures.

  8. seisman commented on Feb 18, 2021

    @seisman
    Member

    Or we could document the behavior of pygmt.config() better.

  9. added
    documentation
    help wanted
    on Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdocumentationhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions