GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||
GeezerVison is showing github.com — Figure.colorbar: Add note regarding automatic fontsize scaling by yvonnefroehlich · Pull Request #4126 · GenericMappingTools/pygmt Conversation
|
| 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. |
There was an error while loading. Please reload this page.
There was a problem 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:
with pygmt.config(FONT_ANNOT_PRIMARY=...) statement around fig.colorbar, but keep the basemap and other fig.* calls outside.scale_cb_font function in Colorbar annotation size does not change #3041 (comment)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem 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 allFor 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()
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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem 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()
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Wei Ji <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.