Open uliw opened 3 years ago
Setting pygmt.config(FONT_ANNOT="6p")
should work. Could you please provide your full codes?
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()
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()
ah ok, so when issued after creating the figure instance it will work. Thanks!
On Mon, Dec 14, 2020 at 1:13 PM Dongdong Tian notifications@github.com wrote:
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()
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/GenericMappingTools/pygmt/issues/733#issuecomment-744617731, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABWSVAVQF7SSMHINX2NJ55LSUZIVBANCNFSM4U3B6IIQ .
-- Ulrich G. Wortmann https://www.es.utoronto.ca/people/faculty/wortmann-ulrich/ Dept. of Earth Sciences Fax : 416 978 3938 University of Toronto Phone: 416 978 7084 22 Ursula Franklin Street, Toronto, ON, Canada M5S 3B1
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()
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:
fig.destroy()
/fig.clear()
(or similar) methodwith pygmt.Figure() as fig: fig.* ...
to keep the scope of things local.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.
Or we could document the behavior of pygmt.config()
better.
Description of the problem
Setting
appears to have no effect and setting it directly like this
results in a parsing error.
I may not see the forest for trees here... so any pointers are much appreciated
This is
Full code that generated the error
Full error message
System information
Please paste the output of
python -c "import pygmt; pygmt.show_versions()"
: