Skip to content

Colorbar annotation size does not change #3041

Closed

Description

@bjmarfito

Description of the problem

I set the FONT_ANNOT_PRIMARY and FONT_LABEL to 20 but the annotation on the colorbar does not change

Minimal Complete Verifiable Example

import pygmt

pygmt.config(FONT_LABEL = 20)
pygmt.config(FONT_ANNOT_PRIMARY = 20)

fig = pygmt.Figure()
fig.colorbar(position="x+3.68i/0.38i+w1.9i/0.090i+ef+mul+h", frame="a100f50", cmap=cptFileSlip)
fig.show()

Full error message

No response

System information

PyGMT information:
  version: v0.10.0
System information:
  python: 3.11.7 (main, Dec 10 2023, 14:13:07) [Clang 15.0.0 (clang-1500.0.40.1)]
  executable: /opt/local/bin/python
  machine: macOS-14.3-arm64-arm-64bit
Dependency information:
  numpy: 1.26.2
  pandas: 2.1.1
  xarray: 2022.12.0
  netCDF4: 1.6.5
  packaging: 23.2
  contextily: None
  geopandas: None
  IPython: 8.14.0
  rioxarray: None
  ghostscript: 10.02.1
GMT library information:
  binary version: 6.5.0
  cores: 10
  grid layout: rows
  image layout: 
  library path: /opt/local/lib/gmt6/lib/libgmt.dylib
  padding: 2
  plugin dir: /opt/local/lib/gmt6/lib/gmt/plugins
  share dir: /opt/local/lib/gmt6/share/gmt
  version: 6.5.0

Activity

  1. added
    bug
    on Feb 6, 2024
  2. welcome commented on Feb 6, 2024

    @welcome

    👋 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.

  3. weiji14 commented on Feb 6, 2024

    @weiji14
    Member

    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.:

    with pygmt.config(FONT_LABEL="20p", FONT_ANNOT_PRIMARY="20p"):
        fig = pygmt.Figure()
        fig.colorbar(position="x+3.68i/0.38i+w1.9i/0.090i+ef+mul+h", frame="a100f50", cmap=cptFileSlip)
        fig.show()
  4. bjmarfito commented on Feb 6, 2024

    @bjmarfito
    Author

    Hi @weiji14, your proposed fix did not work on my side.

  5. yvonnefroehlich commented on Feb 6, 2024

    @yvonnefroehlich
    Member

    Can you please try to see if it works when config is called after initializing the Figure instance:

    import pygmt
    
    size = 5
    
    # pygmt.config(FONT_LABEL = 20)
    # pygmt.config(FONT_ANNOT_PRIMARY = 20)
    
    fig = pygmt.Figure()
    
    pygmt.config(FONT_LABEL=20)
    pygmt.config(FONT_ANNOT_PRIMARY=20)
    
    fig.basemap(region=[-size, size, -size, size], projection=f"X{size}c", frame=True)
    fig.colorbar(cmap="jet", position="jMC", frame=True)
    
    fig.show()
    # fig.savefig(fname="config_font.png")

    Output figure:
    config_font

  6. weiji14 commented on Feb 6, 2024

    @weiji14
    Member

    Oh yeah, I just remembered #733, the pygmt.config call needs to be placed below fig = pygmt.Figure(). E.g.:

    fig = pygmt.Figure()
    with pygmt.config(
        FONT_LABEL="30p,Helvetica,red", FONT_ANNOT_PRIMARY="30p,Helvetica,red"
    ):
        fig.colorbar(
            position="x+3.68i/0.38i+w1.9i/0.090i+ef+mul+h",
            frame="a0.2f50",
            cmap="batlow",
        )
        fig.savefig("temp30.png")
        fig.show()

    produces:

    temp30

  7. added
    duplicate
    on Feb 6, 2024
  8. bjmarfito commented on Feb 7, 2024

    @bjmarfito
    Author

    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.
    Screenshot 2024-02-07 at 9 55 58 AM

  9. weiji14 commented on Feb 7, 2024

    @weiji14
    Member

    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?

  10. bjmarfito commented on Feb 8, 2024

    @bjmarfito
    Author

    Hi @weiji14, here it is.

    import pygmt
    import os
    import numpy as np
    
    # Define the working directory and change to it
    workDirectory = "/Volumes/jupiter/EQ/gmt_plot"
    os.chdir(workDirectory)
    currentDir = "Current working directory: " + os.getcwd()
    print(currentDir)
    
    # Referenced to epicenter
    hypocenterReferenced = "y"
    
    # Directory for slip distribution color palette
    cptSlip = "/Users/bryan/tools/ScientificColourMaps8/lajolla/lajolla.cpt"
    cptFileSlip = "slip.cpt"
    
    # Directory for LOS color palette
    cptLos = "/Users/bryan/tools/ScientificColourMaps8/vik/vik.cpt"
    cpFileLos = "los.cpt"
    
    # Contour color
    contourColor = "white"
    
    # Slip vector color
    slipVectorColor = "white"
    
    # Define the font size and other parameters
    fontSize = 20
    experimentNo = 1
    slip = "/Volumes/jupiter/EQ/modelling/distributed_rectangular_slip_model/linear1/output/inverse_okada_slip_vertical_plane_linear1_exp{}.txt"\
        .format(experimentNo)
    slipVector = "/Volumes/jupiter/EQ/modelling/distributed_rectangular_slip_model/linear1/output/inverse_okada_slip_vector_vertical_plane_linear1_exp{}.txt"\
        .format(experimentNo)
    
    corner = "/Volumes/jupiter/EQ/modelling/distributed_rectangular_slip_model/linear1/output/inverse_okada_fault_corner_coords_linear1_exp{}.txt"\
        .format(experimentNo)
    
    # Set global PyGMT parameters
    pygmt.config(MAP_ANNOT_OBLIQUE = "lat_parallel")
    pygmt.config(MAP_FRAME_TYPE = "plain")
    pygmt.config(MAP_VECTOR_SHAPE = 0)
    pygmt.config(FORMAT_GEO_MAP = "D")
    pygmt.config(FONT_ANNOT_PRIMARY = 20)
    pygmt.config(FONT_LABEL = 20)
    
    # Extract the local coordinates of the epicenter
    xData = np.loadtxt(slip, comments="#", delimiter=" ", unpack=False\
                       , usecols=(0))
    x = xData[2]
    
    # Extract the local coordinates of the fault corners
    slipCoordinates = np.loadtxt(slip, comments="#", delimiter=" ",\
                              max_rows=1, unpack=False)
    
    hypocenterReferenced.lower()
    if hypocenterReferenced == "y":
        slipCoordinates[0] = slipCoordinates[0] - x
        slipCoordinates[1] = slipCoordinates[1] - x
    else:
        pass
    
    xmin  = slipCoordinates[0]
    xmax  = slipCoordinates[1]
    ymin  = slipCoordinates[2]
    ymax  = slipCoordinates[3]
    
    regslip= [xmin, xmax, ymin, ymax]
    
    slipValue = np.loadtxt(slip, comments="#", delimiter=" ", skiprows=6)
    slipValue[:,0] = slipValue[:,0] - x
    
    slipxyz= "slip.xyz"
    np.savetxt(slipxyz, slipValue, fmt="%f", delimiter=" ")
    
    # Use gmtconvert to translate the slip file to a grid file
    commandScript = "gmt gmtconvert {} -bo > slip.b".format(slipxyz)
    os.system(commandScript)
    
    # Smoothened slip distribution using a median filter
    incx = "5m"
    incy = "5m"
    slipgrd = "slip.grd"
    filteredSlipDist = pygmt.blockmedian("slip.b", binary = "i" , spacing = incx + "/" + incy, region = regslip)
    pygmt.surface(filteredSlipDist,region = regslip, binary ="i3" , spacing = incx + "/" + incy, outgrid = slipgrd)
    
    # Create a color palette for slip distribution
    pygmt.makecpt(cmap=cptSlip, series=[0,300,1] , output=cptFileSlip,\
                  background=True, continuous=True, reverse=True)
    
    # Create a color palette for LOS
    pygmt.makecpt(cmap=cptLos, series=[-30,30,1], background=True,\
                  continuous=True, output=cpFileLos)
    
    # Initialize the figure
    fig = pygmt.Figure()
    # Plot basemap
    fig.basemap(projection = "X5.85i/3.58125i", region = regslip,\
                        frame = ["xa5f5+lDistance from the epicenter (km)", \
                                 "y5f2.5+lDepth (km)", "WSne"], xshift = "c", yshift = "c")
    
    # Plot the slip distribution
    fig.grdimage(slipgrd, cmap = cptFileSlip)
    
    #Plot the slip vector
    slipVectorData = np.loadtxt(slipVector, comments="#", delimiter=" ", unpack=False)
    slipVectorData[:,0] = slipVectorData[:,0] - x
    slipVectorData[:,3] = slipVectorData[:,3] /400
    
    # Plot the slip vector
    fig.plot(data = slipVectorData, style= "v0.07i+e", fill = slipVectorColor, pen = "thin,{}".format(slipVectorColor))
    
    # Plot the contour interval
    fig.grdcontour(slipgrd, interval = 50, limit = [10, 150], \
                   pen="thinnest,{}".format(contourColor), \
                    annotation =(50,"f{}".format(fontSize),"r2"), \
                    label_placement = "d3.1i"
                    )
    
    fig.grdcontour(slipgrd, interval = 50, limit = [170, 250], \
                   pen="thinnest,{}".format(contourColor), \
                    annotation =(50,"f{}".format(fontSize),"r2"), \
                    label_placement = "d3.1i"
                    )
    
    # Extract epicenter value and plot it
    epicenterValue = np.loadtxt(slip, comments="#", delimiter=" ", skiprows=5, max_rows=1)
    epicenterValue = epicenterValue[0:2]
    epicenterValue[0] = epicenterValue[0] - x
    epicenterValue[1] = -1 * epicenterValue[1]
    fig.plot(x=epicenterValue[0],y=epicenterValue[1], style = "a0.3i", fill="red", pen="1,black")
    
    # Save the figure
    fig.savefig("slip.pdf", dpi=300)
    #fig.show()
  11. weiji14 commented on Feb 8, 2024

    @weiji14
    Member

    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?

  12. bjmarfito commented on Feb 8, 2024

    @bjmarfito
    Author

    Hi @weiji14, this is the modified version. Still does not work on my side. Sorry about the wrong code I posted.

    import pygmt
    import os
    import numpy as np
    
    # Define the working directory and change to it
    workDirectory = "/Volumes/jupiter/EQ/modelling/inversion_kaj"
    os.chdir(workDirectory)
    currentDir = "Current working directory: " + os.getcwd()
    print(currentDir)
    
    # Referenced to epicenter
    hypocenterReferenced = "y"
    
    # Directory for slip distribution color palette
    cptSlip = "/Users/bryan/tools/ScientificColourMaps8/lajolla/lajolla.cpt"
    cptFileSlip = "slip.cpt"
    
    # Directory for LOS color palette
    cptLos = "/Users/bryan/tools/ScientificColourMaps8/vik/vik.cpt"
    cpFileLos = "los.cpt"
    
    # Contour color
    contourColor = "white"
    
    # Slip vector color
    slipVectorColor = "white"
    
    # Shoreline style
    shorelineStyle = "2"
    
    # Subsurface slip projection
    subslipProjection  = "X5.85i/3.58125i"
    
    # Surface deformation projection
    surfaceDefProjection = "M3i"
    
    # Satellite data region
    satRegion =[69.2,69.9,32.8,33.3]
    
    # Define the font size and other parameters
    fontSize = 20
    experimentNo = 1
    slip = "/Volumes/jupiter/EQ/modelling/inversion_kaj/slipData_GMTplot.txt"
    slipVector = "/Volumes/jupiter/EQ/modelling/distributed_rectangular_slip_model/linear1/output/inverse_okada_slip_vector_vertical_plane_linear1_exp{}.txt"\
        .format(experimentNo)
    
    corner = "/Volumes/jupiter/EQ/modelling/distributed_rectangular_slip_model/linear1/output/inverse_okada_fault_corner_coords_linear1_exp{}.txt"\
        .format(experimentNo)
    
    # Set global PyGMT parameters
    pygmt.config(MAP_ANNOT_OBLIQUE = "lat_parallel")
    pygmt.config(MAP_FRAME_TYPE = "plain")
    pygmt.config(MAP_VECTOR_SHAPE = 0)
    pygmt.config(FORMAT_GEO_MAP = "D")
    pygmt.config(FONT_ANNOT_PRIMARY = "20p,Helvetica")
    pygmt.config(FONT_LABEL = "20p,Helvetica")
    
    # Extract the local coordinates of the epicenter
    xData = np.loadtxt(slip, comments="#", delimiter=" ", unpack=False\
                       , usecols=(0))
    x = xData[2]
    
    # Extract the local coordinates of the fault corners
    slipCoordinates = np.loadtxt(slip, comments="#", delimiter=" ",\
                              max_rows=1, unpack=False)
    
    hypocenterReferenced.lower()
    if hypocenterReferenced == "y":
        slipCoordinates[0] = slipCoordinates[0] - x
        slipCoordinates[1] = slipCoordinates[1] - x
    else:
        pass
    
    xmin  = slipCoordinates[0]
    xmax  = slipCoordinates[1]
    ymin  = slipCoordinates[2]
    ymax  = slipCoordinates[3]
    
    regslip= [xmin, xmax, ymin, ymax]
    
    slipValue = np.loadtxt(slip, comments="#", delimiter=" ", skiprows=6)
    slipValue[:,0] = slipValue[:,0] - x
    
    slipxyz= "slip.xyz"
    np.savetxt(slipxyz, slipValue, fmt="%f", delimiter=" ")
    
    # Use GMT convert to convert the slip file to a grid file
    commandScript = "gmt gmtconvert {} -bo > slip.b".format(slipxyz)
    os.system(commandScript)
    
    # Smoothened slip distribution using a median filter
    incx = "5m"
    incy = "5m"
    slipgrd = "slip.grd"
    filteredSlipDist = pygmt.blockmedian("slip.b", binary = "i" , spacing = incx + "/" + incy, region = regslip)
    pygmt.surface(filteredSlipDist,region = regslip, binary ="i3" , spacing = incx + "/" + incy, outgrid = slipgrd)
    
    # Create a color palette for slip distribution
    pygmt.makecpt(cmap=cptSlip, series=[0,300,1] , output=cptFileSlip,\
                  background=True, continuous=True, reverse=True)
    
    # Create a color palette for LOS
    pygmt.makecpt(cmap=cptLos, series=[-30,30,1], background=True,\
                  continuous=True, output=cpFileLos)
    
    # Initialize the figure
    fig = pygmt.Figure()
    with pygmt.config(FONT_LABEL="20p,Helvetica", FONT_ANNOT_PRIMARY="20p,Helvetica"):
    # Plot basemap
        fig.basemap(projection = subslipProjection, region = regslip,\
                        frame = ["xa5f5+lDistance from the epicenter (km)", \
                                 "y5f2.5+lDepth (km)", "WSne"], xshift = "c", yshift = "c")
    
        # Plot the slip distribution
        fig.grdimage(slipgrd, cmap = cptFileSlip)
    
        # Plot the slip vector
        # slipVectorData = np.loadtxt(slipVector, comments="#", delimiter=" ", unpack=False)
        # slipVectorData[:,0] = slipVectorData[:,0] - x
        # slipVectorData[:,3] = slipVectorData[:,3] /400
    
        # Plot the slip vector
        # fig.plot(data = slipVectorData, style= "v0.07i+e", fill = slipVectorColor, pen = "thin,{}".format(slipVectorColor))
    
        # Plot the contour interval
        fig.grdcontour(slipgrd, interval = 50, limit = [10, 150], \
                   pen="thinnest,{}".format(contourColor), \
                    annotation =(50,"f{}".format(fontSize),"r2"), \
                    label_placement = "d3.1i"
                    )
    
        fig.grdcontour(slipgrd, interval = 50, limit = [170, 250], \
                   pen="thinnest,{}".format(contourColor), \
                    annotation =(50,"f{}".format(fontSize),"r2"), \
                    label_placement = "d3.1i"
                    )
    
        fig.colorbar(position="x+3.68i/0.38i+w1.9i/0.090i+ef+mul+h", frame="a100f50", \
                     cmap=cptFileSlip)
        fig.text(text="cm", x = 9.0, y= -9.2)
        fig.text(text = "SW", x = 11.2, y= 0.4)
        fig.text(text = "NE", x = -5, y= 0.4)
    
        # Extract epicenter value and plot it
        epicenterValue = np.loadtxt(slip, comments="#", delimiter=" ", skiprows=5, max_rows=1)
        epicenterValue = epicenterValue[0:2]
        epicenterValue[0] = epicenterValue[0] - x
        epicenterValue[1] = -1 * epicenterValue[1]
        fig.plot(x=epicenterValue[0],y=epicenterValue[1], style = "a0.3i", fill="red", \
                 pen="1,black")
    
        # Plot the data points
        fig.coast(region = satRegion, land=contourColor, resolution="f",\
                   shorelines = shorelineStyle, projection = surfaceDefProjection, \
                    water = "azure", frame = ["WSne", "xa.3f.3","y.2f.2" ], xshift = -10, yshift = -3)
        # Save the figure
        fig.savefig("slip.pdf", dpi=300)
        #fig.show()
  13. yvonnefroehlich commented on Feb 8, 2024

    @yvonnefroehlich
    Member

    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?

  14. bjmarfito commented on Feb 9, 2024

    @bjmarfito
    Author

    Hi @yvonnefroehlich, the issue is the first one where the colorbar annotation font size does not change.

  15. seisman commented on Feb 18, 2024

    @seisman
    Member

    @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.

  16. 7 remaining items

  17. leouieda commented on Aug 25, 2025

    @leouieda
    Member

    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:

    import pygmt
    
    size = 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 manager
    with pygmt.config(
        FONT_ANNOT_PRIMARY="17p,blue", 
        FONT_ANNOT_SECONDARY="15p,darkgreen",
        FONT_LABEL="20p,orange",
    ):
        # Move basemap inside the config
        fig.basemap(region=[-size, size, -size, size], projection=f"X{size}c", frame=1)
        # Primary annotations should be same size but they aren't
        fig.colorbar(cmap="batlow", position="jMC", frame=["x+lquantity", "y+lunit"])
    fig.show()
    (I) (II)
    Image Image

    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:

    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!).

  18. yvonnefroehlich commented on Aug 26, 2025

    @yvonnefroehlich
    Member

    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:

    import pygmt
    import numpy as np
    
    plot_size = 5
    font_size = 7
    
    cb1_width = 4
    cb2_width = 2
    cb1_label = "cb1 is long"
    cb2_label = "cb2 is short"
    
    # -----------------------------------------------------------------------------
    def scale_cb_font(cb_width):
        scale_factor = 1 / 15  # scale factor used in GMT 6.5
        font_scaling = np.sqrt(cb_width * scale_factor)
        return font_scaling
    # -----------------------------------------------------------------------------
    
    fig = pygmt.Figure()
    
    # (Left)
    pygmt.config(FONT=font_size)
    fig.basemap(region=[-plot_size, plot_size] * 2, projection=f"X{plot_size}c", frame=1)
    
    fig.colorbar(cmap="navia", position=f"jTC+w{cb1_width}c+h", frame=f"x+l{cb1_label}")
    fig.colorbar(cmap="navia", position=f"jBC+w{cb2_width}c+h", frame=f"x+l{cb2_label}")
    
    fig.shift_origin(xshift="6c")
    
    # (Right)
    with pygmt.config(FONT=font_size):
        fig.basemap(region=[-plot_size, plot_size] * 2, projection=f"X{plot_size}c", frame=1)
    
    font_scaling1 = scale_cb_font(cb1_width)
    with pygmt.config(FONT=f"{font_size / font_scaling1}"):
        fig.colorbar(cmap="navia", position=f"jTC+w{cb1_width}c+h", frame=f"x+l{cb1_label}")
    font_scaling2 = scale_cb_font(cb2_width)
    with pygmt.config(FONT=f"{font_size / font_scaling2}"):
        fig.colorbar(cmap="navia", position=f"jBC+w{cb2_width}c+h", frame=f"x+l{cb2_label}")
    
    fig.show()
    Image
  19. leouieda commented on Aug 26, 2025

    @leouieda
    Member

    @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/

  20. yvonnefroehlich commented on Sep 4, 2025

    @yvonnefroehlich
    Member

    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.

  21. added
    triage
    upstream
    and removed
    duplicate
    on Oct 4, 2025
  22. weiji14 commented on Oct 4, 2025

    @weiji14
    Member

    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.

  23. yvonnefroehlich commented on Oct 4, 2025

    @yvonnefroehlich
    Member

    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=...).

  24. weiji14 commented on Oct 7, 2025

    @weiji14
    Member

    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.

  25. weiji14 commented on Oct 7, 2025

    @weiji14
    Member

    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:

    pygmt/pygmt/helpers/utils.py

    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.

  26. leouieda commented on Oct 7, 2025

    @leouieda
    Member

    I would say that this has been covered in #455

    @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.

  27. yvonnefroehlich commented on Jul 30, 2026

    @yvonnefroehlich
    Member

    @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.

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

    triageupstream

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions