Skip to content
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

changing map annotation font size #733

Open
uliw opened this issue Dec 14, 2020 · 7 comments
Open

changing map annotation font size #733

uliw opened this issue Dec 14, 2020 · 7 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation help wanted Helping hands are appreciated

Comments

@uliw
Copy link

uliw commented Dec 14, 2020

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
@seisman
Copy link
Member

seisman commented Dec 14, 2020

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

@uliw
Copy link
Author

uliw commented Dec 14, 2020

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()

@seisman
Copy link
Member

seisman commented Dec 14, 2020

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()

@seisman seisman added the bug Something isn't working label Dec 14, 2020
@uliw
Copy link
Author

uliw commented Dec 14, 2020 via email

@seisman
Copy link
Member

seisman commented Dec 14, 2020

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()

@weiji14
Copy link
Member

weiji14 commented Feb 17, 2021

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.

@seisman
Copy link
Member

seisman commented Feb 18, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation help wanted Helping hands are appreciated
Projects
None yet
Development

No branches or pull requests

3 participants