You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.
Hmm, could you post your full code, at least the part including fig.basemap? Are you plotting the colorbar in a subplot, inset or just a single figure?
Hmm, I don't see where you are calling fig.colorbar, and all your pygmt.config calls are still above the fig = pygmt.Figure() line. Is this the correct modified version?
Thanks @bjmarfito for posting your code (if you write ```python at the beginning of your code block your get code highlighting related to python 🙂).
The annotation font on the colorbar is still smaller compare to the grid annotation.
Just to be clear about your question: Is your issue, that the font size does not change via pygmt.config() or that map frame annotations and colorbar annotations do not appear in the same font size?
@bjmarfito Both @yvonnefroehlich and @weiji14's examples work for me, so I bet there must be something wrong on your side. You need to provide all datasets used in your script or provide a minimal example so that we can reproduce your issue. Otherwise, there will be very little we can do to help you.
Hi all, reopening this because it's still an issue. This is to do with this line from gmt colorbar:
But mind you that the modern mode theme scales down the size of annotations and labels based on the colorbar length for improved legibility. So, in modern mode scripts it might look that these parameter settings are not working correctly. If you may want to increase font sizes to compensate the scaling effect the solution is to use the online --FONT_ANNOT_PRIMARY=... construct.
So the colorbar is not respecting the GMT config values. In fact, looking at @yvonnefroehlich's example we can see that this is the case if we move the basemap call inside the with block:
importpygmtsize=5# (I)fig=pygmt.Figure()
fig.basemap(region=[-size, size, -size, size], projection=f"X{size}c", frame=1)
fig.colorbar(cmap="batlow", position="jMC", frame=["x+lquantity", "y+lunit"])
fig.show()
# (II)fig=pygmt.Figure()
# local changes of GMT defaults via context managerwithpygmt.config(
FONT_ANNOT_PRIMARY="17p,blue",
FONT_ANNOT_SECONDARY="15p,darkgreen",
FONT_LABEL="20p,orange",
):
# Move basemap inside the configfig.basemap(region=[-size, size, -size, size], projection=f"X{size}c", frame=1)
# Primary annotations should be same size but they aren'tfig.colorbar(cmap="batlow", position="jMC", frame=["x+lquantity", "y+lunit"])
fig.show()
(I)
(II)
Notice that the colorbar and axis annotations should all be 17p but the colorbar clearly has smaller font size.
The only way around this is to allow PyGMT methods to take the --FONT_ANNOT_PRIMARY and other config values so they can be set per module. Fortunately, build_arg_list already functionality for handling a config dictionary:
@yvonnefroehlich thanks for the example! Yes, I found this a bit baffling since it usually makes the font way too small and it's not really what I'd expect the default behavior to be.
@arthursmacedo check out the code above to use in your figure/
Yes, I found this a bit baffling since it usually makes the font way too small and it's not really what I'd expect the default behavior to be.
I agree, and I am personally not a big fan of this newly added automatic font size scaling. If having two colorbars with different widths in the same figure, it can be strange to have different font sizes. Based on feedback from some colleagues, there was also some confusion about this change.
Just want to mention that there was the suggestion by @leouieda in #3041 (comment)
to use the new alias system to allow adjusting the GMT defaults directly within the single plotting methods (see classic mode of GMT, e.g.,--FONT_ANNOT_PRIMARY=...).
Just want to mention that there was the suggestion by @leouieda in #3041 (comment) to use the new alias system to allow adjusting the GMT defaults directly within the single plotting methods (see classic mode of GMT, e.g.,--FONT_ANNOT_PRIMARY=...).
I would say that this has been covered in #455, i.e. just use a with pygmt.config(...) statement covering the single line you want to override the config for. But see also some related discussions in #3252 on where this might not work in certain cases.
The only way around this is to allow PyGMT methods to take the --FONT_ANNOT_PRIMARY and other config values so they can be set per module. Fortunately, build_arg_list already functionality for handling a config dictionary:
Line 486 in 5d2da64
confdict: Mapping[str, Any] | None = None,
It just needs to be plugged into the alias system (I just had a look at the "new" one and great job on that everyone!).
And just on this, the build_arg_string(confdict=...) setting is only for internal use as mentioned at #2299. We've added this to configure the font for timestamp in #2208, because FONT_LOGO was a special case I think from reading #2208 (comment). Could open a new feature request if there's interest in expanding this to other modules.
@weiji14 it's not since the GMT docs say that setting the font by gmt config doesn't disable the scaling but setting it though the command line argument to the module does. So we'd need to pass --FONT_ANNOT_PRIMARY to colobar through the CallModule API.
@leouieda just want to mention that GMT 6.7.0 has just been released and introduces -H for colorbar to not have the automatic scaling of the colorbar font size based on the colorbar width applied:
From GMT 6.5 on, colorbar annotation fonts are auto-scaled. Use this option to prevent that effect and let user set fonts as they wish.
Maybe this can be helpful and can reduce the confusion. Will need to test this and think about adding an alias for -H at #4243.
Activity
welcome commentedon Feb 6, 2024
👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.
weiji14 commentedon Feb 6, 2024
Hmm, not very well documented at https://docs.generic-mapping-tools.org/6.5/gmt.conf.html#term-FONT_LABEL, but could you try adding
p(for the unit 'point') and see if it works? E.g.:bjmarfito commentedon Feb 6, 2024
Hi @weiji14, your proposed fix did not work on my side.
yvonnefroehlich commentedon Feb 6, 2024
Can you please try to see if it works when
configis called after initializing theFigureinstance:Output figure:

weiji14 commentedon Feb 6, 2024
Oh yeah, I just remembered #733, the
pygmt.configcall needs to be placed belowfig = pygmt.Figure(). E.g.:produces:
bjmarfito commentedon Feb 7, 2024
Hi @weiji14 , the fix still does not work on my side. The annotation font on the colorbar is still smaller compare to the grid annotation.

weiji14 commentedon Feb 7, 2024
Hmm, could you post your full code, at least the part including
fig.basemap? Are you plotting the colorbar in a subplot, inset or just a single figure?bjmarfito commentedon Feb 8, 2024
Hi @weiji14, here it is.
weiji14 commentedon Feb 8, 2024
Hmm, I don't see where you are calling
fig.colorbar, and all yourpygmt.configcalls are still above thefig = pygmt.Figure()line. Is this the correct modified version?bjmarfito commentedon Feb 8, 2024
Hi @weiji14, this is the modified version. Still does not work on my side. Sorry about the wrong code I posted.
yvonnefroehlich commentedon Feb 8, 2024
Thanks @bjmarfito for posting your code (if you write
```pythonat the beginning of your code block your get code highlighting related to python 🙂).Just to be clear about your question: Is your issue, that the font size does not change via
pygmt.config()or that map frame annotations and colorbar annotations do not appear in the same font size?bjmarfito commentedon Feb 9, 2024
Hi @yvonnefroehlich, the issue is the first one where the colorbar annotation font size does not change.
seisman commentedon Feb 18, 2024
@bjmarfito Both @yvonnefroehlich and @weiji14's examples work for me, so I bet there must be something wrong on your side. You need to provide all datasets used in your script or provide a minimal example so that we can reproduce your issue. Otherwise, there will be very little we can do to help you.
7 remaining items
leouieda commentedon Aug 25, 2025
Hi all, reopening this because it's still an issue. This is to do with this line from
gmt colorbar:So the colorbar is not respecting the GMT config values. In fact, looking at @yvonnefroehlich's example we can see that this is the case if we move the
basemapcall inside thewithblock:Notice that the colorbar and axis annotations should all be
17pbut the colorbar clearly has smaller font size.The only way around this is to allow PyGMT methods to take the
--FONT_ANNOT_PRIMARYand other config values so they can be set per module. Fortunately,build_arg_listalready functionality for handling a config dictionary:pygmt/pygmt/helpers/utils.py
Line 486 in 5d2da64
yvonnefroehlich commentedon Aug 26, 2025
I agree that it would be good to allow users to overwrite the automatic scaling of font size of the colorbar based on the width of the colorbar (introduced in GMT 6.5; see GenericMappingTools/gmt#6802) also in modern mode. There were some confusions and discussions on the forum, e.g., https://forum.generic-mapping-tools.org/t/multiple-colorbars-changes-the-annotation-fontsize/4945. Currently I manually redo the scaling:
leouieda commentedon Aug 26, 2025
@yvonnefroehlich thanks for the example! Yes, I found this a bit baffling since it usually makes the font way too small and it's not really what I'd expect the default behavior to be.
@arthursmacedo check out the code above to use in your figure/
yvonnefroehlich commentedon Sep 4, 2025
I agree, and I am personally not a big fan of this newly added automatic font size scaling. If having two colorbars with different widths in the same figure, it can be strange to have different font sizes. Based on feedback from some colleagues, there was also some confusion about this change.
weiji14 commentedon Oct 4, 2025
We've documented a workaround in PR #4126 (see note under https://www.pygmt.org/v0.17.0/api/generated/pygmt.Figure.colorbar.html) based on reversing the scaling factor, so will close this now. Let's move the discussion upstream to GenericMappingTools/gmt#8796 if we want GMT itself to change the default behaviour.
yvonnefroehlich commentedon Oct 4, 2025
Just want to mention that there was the suggestion by @leouieda in #3041 (comment)
to use the new alias system to allow adjusting the GMT defaults directly within the single plotting methods (see classic mode of GMT, e.g.,
--FONT_ANNOT_PRIMARY=...).weiji14 commentedon Oct 7, 2025
I would say that this has been covered in #455, i.e. just use a
with pygmt.config(...)statement covering the single line you want to override the config for. But see also some related discussions in #3252 on where this might not work in certain cases.weiji14 commentedon Oct 7, 2025
And just on this, the
build_arg_string(confdict=...)setting is only for internal use as mentioned at #2299. We've added this to configure the font fortimestampin #2208, becauseFONT_LOGOwas a special case I think from reading #2208 (comment). Could open a new feature request if there's interest in expanding this to other modules.leouieda commentedon Oct 7, 2025
@weiji14 it's not since the GMT docs say that setting the font by
gmt configdoesn't disable the scaling but setting it though the command line argument to the module does. So we'd need to pass--FONT_ANNOT_PRIMARYtocolobarthrough theCallModuleAPI.yvonnefroehlich commentedon Jul 30, 2026
@leouieda just want to mention that GMT 6.7.0 has just been released and introduces -H for
colorbarto not have the automatic scaling of the colorbar font size based on the colorbar width applied:Maybe this can be helpful and can reduce the confusion. Will need to test this and think about adding an alias for -H at #4243.