GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Figure.colorbar: Add note regarding automatic fontsize scaling by yvonnefroehlich · Pull Request #4126 · GenericMappingTools/pygmt

Conversation

@yvonnefroehlich

@yvonnefroehlich yvonnefroehlich commented Sep 29, 2025 •
edited by weiji14
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Description of proposed changes

There are several reports and posts on GitHub and the GMT forum regarding the automatic scaling of the fontsize of the colorbar label up on GMT 6.5. Maybe adding a note to the documentation for Figure.colorbar makes this change more visible to users.

GMT docs dev: https://docs.generic-mapping-tools.org/dev/colorbar.html#description

Preview: https://pygmt-dev--4126.org.readthedocs.build/en/4126/api/generated/pygmt.Figure.colorbar.html

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash command is:

  • /format: automatically format and lint the code

Address #3041

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mnergizci reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@yvonnefroehlich
Add note regarding automatic fontsize scaling
13590f6
@yvonnefroehlich yvonnefroehlich added this to the 0.17.0 milestone Sep 29, 2025
@yvonnefroehlich yvonnefroehlich self-assigned this Sep 29, 2025
@yvonnefroehlich yvonnefroehlich added the documentation Improvements or additions to documentation label Sep 29, 2025
yvonnefroehlich added 3 commits September 29, 2025 14:57
@yvonnefroehlich
Add more information
0c55a48
@yvonnefroehlich
Use math mode
1fded9b
@yvonnefroehlich
Fix math synthax
f56ae84
@yvonnefroehlich
yvonnefroehlich marked this pull request as draft September 29, 2025 14:20
yvonnefroehlich and others added 5 commits September 29, 2025 16:28
@yvonnefroehlich
Remove underscore
0e27f13
@yvonnefroehlich
Merge branch 'main' into add-note-fontsize-cb
2e29446
@yvonnefroehlich
Add more information
693be21
@yvonnefroehlich
Merge remote-tracking branch 'origin/add-note-fontsize-cb' into add-n…
4e05d24
…ote-fontsize-cb
@yvonnefroehlich
Merge branch 'main' into add-note-fontsize-cb
8248cda
@yvonnefroehlich
yvonnefroehlich marked this pull request as ready for review September 29, 2025 18:26
@yvonnefroehlich
Merge branch 'main' into add-note-fontsize-cb
c4066b8
@yvonnefroehlich yvonnefroehlich added the needs review This PR has higher priority and needs review. label Sep 30, 2025
@yvonnefroehlich yvonnefroehlich mentioned this pull request Sep 30, 2025
Release PyGMT v0.17.0 #4100
Closed
38 of 43 tasks
yvonnefroehlich and others added 5 commits September 30, 2025 16:49
@yvonnefroehlich
Merge branch 'main' into add-note-fontsize-cb
c9ea951
@yvonnefroehlich
Merge branch 'main' into add-note-fontsize-cb
19c3046
@yvonnefroehlich
TEST: fix docs warning regarding pattern class
b3c6ada
@yvonnefroehlich
TEST: Use 'Parameters'
35dad14
@yvonnefroehlich
Revert change
7f05b32
weiji14
weiji14 reviewed Sep 30, 2025
View reviewed changes
Comment thread pygmt/src/colorbar.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pygmt/src/colorbar.py Outdated
Comment on lines +54 to +56
width of the colorbar (:math:`\sqrt{{colorbarwidth / 15}}`). Currently, in
modern mode, changing this fontsize via adjusting the GMT default parameter
:gmt-term:`FONT_LABEL` does not work as expected.

@weiji14 weiji14 Sep 30, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saw your post at https://forum.generic-mapping-tools.org/t/longitude-axis-starts-at-0-instead-of-my-region-bounds-when-using-mercator-projection-in-pygmt/6214/4, and the link to https://docs.generic-mapping-tools.org/dev/colorbar.html#description which suggests using --FONT_ANNOT_PRIMARY=....

Based on your example at #3041 (comment), is the recommendation to use:

fig.basemap(...)
with pygmt.config(FONT=...):
    fig.colorbar(cmap="...", ...)

Or can we maybe suggest using FONT_ANNOT_PRIMARY? I think the key is to:

  1. Only wrap the with pygmt.config(FONT_ANNOT_PRIMARY=...) statement around fig.colorbar, but keep the basemap and other fig.* calls outside.
  2. Apply the scaling factor using your scale_cb_font function in Colorbar annotation size does not change #3041 (comment)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@yvonnefroehlich yvonnefroehlich Sep 30, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. I think it's FONT_LABEL for the x-axis label. because as far as I understood it:

  • FONT_ANNOT_PRIMARY: fontsize of the x-axis annotations (numbers)
  • FONT_ANNOT_SECONDARY: fontsize of the y-axis label (-> unit)
  • FONT_LABEL: fontsize of the x-axis label (-> quantity)
  • FONT: fontsize of all

For me, FONT_ANNOT_PRIMARY has no effect on the x-axis label:

import pygmt

size = 5
args_bmap = {"region": [-1, 1, -size, size], "projection": f"X4c/{size}c", "frame": 1}
args_cb = {"cmap": "batlow", "position": "jMC", "frame": ["x+lquantity", "y+lunit"]}

fig = pygmt.Figure()

# -----------------------------------------------------------------------------
fig.basemap(**args_bmap)

fig.colorbar(**args_cb)

# -----------------------------------------------------------------------------
fig.shift_origin(xshift="+w+1c")
fig.basemap(**args_bmap)

with pygmt.config(
    FONT_ANNOT_PRIMARY="10p,blue",  # x-axis annotations (numbers)
    FONT_ANNOT_SECONDARY="20p,darkgreen",  # y-axis label (-> unit)
    FONT_LABEL="20p,orange",  # x-axis label (-> quantity)
):
    fig.colorbar(**args_cb)

# -----------------------------------------------------------------------------
fig.shift_origin(xshift="+w+1c")
fig.basemap(**args_bmap)

with pygmt.config(
    FONT_ANNOT_PRIMARY="25p,blue", 
    FONT_ANNOT_SECONDARY="20p,darkgreen",
    FONT_LABEL="20p,orange",
):
    fig.colorbar(**args_cb)

# -----------------------------------------------------------------------------
fig.shift_origin(xshift="+w+1c")
fig.basemap(**args_bmap)

with pygmt.config(
    FONT_ANNOT_PRIMARY="25p,blue", 
    FONT_ANNOT_SECONDARY="20p,darkgreen",
    # FONT_LABEL="20p,orange",
):
    fig.colorbar(**args_cb)

fig.show()
colorbar_width_label_fontsize

I am fine with including an explicit workaround. Yes, the user has to adjust the desired font size based on the scale factor (previously calculated using the colorbar width) and pass this value to FONT_LABEL (or FONT). The automatic font size scaling reverts this adjustment, and the desired font size is applied. This has to be done locally (with config(...): ) to avoid affecting the font sizes related to the figure frame (basemap) because here no automatic font size scaling is applied.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@weiji14 weiji14 Sep 30, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Leo's code at #3041 (comment), it seems like it is not just the colorbar label (set by FONT_LABEL) which is affected by the scaling factor, but also the x- and y- axis annotations (set by FONT_ANNOT_PRIMARY and FONT_ANNOT_SECONDARY respectively). So probably should mention all of these. Could you update the text to reflect that both the label and annotations are affected?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

yvonnefroehlich reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@yvonnefroehlich yvonnefroehlich Oct 1, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the fontsizes of x-label, x-axis annotations and y-label are affect, and it looks like they all use the same scaling, see code and figure below. I have extended the text in 870be82.


import pygmt
import numpy as np

# -----------------------------------------------------------------------------
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
# -----------------------------------------------------------------------------

font_size = 18

plot_size = 5
args_bmap = {
    "region": [-1, 1, -plot_size, plot_size], "projection": f"X4c/{plot_size}c", "frame": 1}

cb_width = 4
args_cb = {
    "cmap": "batlow", "position": f"jMC+w{cb_width}c", "frame": ["x+lquantity", "y+lunit"]
}
font_scaling = scale_cb_font(cb_width)

# -----------------------------------------------------------------------------
fig = pygmt.Figure()

# Left
fig.basemap(**args_bmap)

fig.colorbar(**args_cb)

# Middle
fig.shift_origin(xshift="+w+1c")

with pygmt.config(
    FONT_ANNOT_PRIMARY=f"{font_size}p",  # x-axis annotations (-> numbers)
    FONT_ANNOT_SECONDARY=f"{font_size}p",  # y-axis label (-> unit)
    FONT_LABEL=f"{font_size}p",  # x-axis label (-> quantity)
    # FONT=f"{font_size}p"  # all
):
    fig.basemap(**args_bmap)

    fig.colorbar(**args_cb)

# Right
fig.shift_origin(xshift="+w+1c")

with pygmt.config(FONT=font_size):
    fig.basemap(**args_bmap)

with pygmt.config(
    FONT_ANNOT_PRIMARY=f"{font_size / font_scaling}p",
    FONT_ANNOT_SECONDARY=f"{font_size / font_scaling}p",
    FONT_LABEL=f"{font_size / font_scaling}p",
):
    fig.colorbar(**args_cb)

fig.show()
cb_font_scaling_02

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

weiji14 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
yvonnefroehlich and others added 5 commits September 30, 2025 23:11
@yvonnefroehlich @weiji14
Improve formulation
d6bef9a
Co-authored-by: Wei Ji <[email protected]>
@yvonnefroehlich
Fix line length
f514e26
@yvonnefroehlich
Improve formulation to account for all fontsizes and provide workaround
870be82
@yvonnefroehlich
Fix hilighting for code
3bdf1fd
@yvonnefroehlich
Merge branch 'main' into add-note-fontsize-cb
59c9518
weiji14
weiji14 approved these changes Oct 1, 2025
View reviewed changes

@weiji14 weiji14 left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @yvonnefroehlich, I'll merge this after one minor change.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pygmt/src/colorbar.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@yvonnefroehlich @weiji14
Improve formulation and grammar
513840a
Co-authored-by: Wei Ji <[email protected]>
@weiji14
weiji14 merged commit 35f06da into main Oct 1, 2025
@weiji14
weiji14 deleted the add-note-fontsize-cb branch October 1, 2025 21:00
@seisman seisman removed the needs review This PR has higher priority and needs review. label Oct 2, 2025
@weiji14 weiji14 mentioned this pull request Oct 4, 2025
Colorbar annotation size does not change #3041
Closed
@yvonnefroehlich yvonnefroehlich mentioned this pull request Oct 5, 2025
DOC: Fix typo in note for colorbar fontsize scaling #4139
Merged
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@weiji14 weiji14 weiji14 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@yvonnefroehlich yvonnefroehlich

Labels

documentation Improvements or additions to documentation

Projects

None yet

Milestone

0.17.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@yvonnefroehlich @weiji14 @seisman
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.