Skip to content

Conversation

@seisman
Copy link
Member

@seisman seisman commented Jul 26, 2025

This PR implements the Figure.scalebar method, which wraps the -L option in basemap/coast. Related to #4268.

The full syntax of -L is:

-L[g|j|J|n|x]refpoint+wlength[e|f|k|M|n|u][+aalign][+c[[slon/]slat]][+f][+jjustify][+l[label]][+odx[/dy]][+u][+v]

Here is a comparison of names used in PyGMT, GMT, and GMT.jl:

modifier PyGMT GMT GMT.jl
+w length length length
+a label_alignment align align
+c scale_position loc scale_at_lat
+l label label label
+u unit units units
+v vertical vertical vertical

Preview: https://pygmt-dev--4015.org.readthedocs.build/en/4015/api/generated/pygmt.Figure.scalebar.html#pygmt.Figure.scalebar

TODO in separate PRs

  • Update gallery examples using the new scalebar method
  • Deprecate map_scale in Figure.coast/Figure.basemap
  • Update the example in the paper

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

Summary of changed images

This is an auto-generated report of images that have changed on the DVC remote

Status Path
added pygmt/tests/baseline/test_scalebar.png
added pygmt/tests/baseline/test_scalebar_cartesian.png
added pygmt/tests/baseline/test_scalebar_complete.png

Image diff(s)

Details

Added images

  • test_scalebar.png

  • test_scalebar_cartesian.png

  • test_scalebar_complete.png

Modified images

Path Old New

Report last updated at commit 78cd352

@seisman seisman changed the title WIP: Add Figure.scalebar to plot a scale bar on maps \Add Figure.scalebar to plot a scale bar on maps Dec 10, 2025
@seisman seisman changed the title \Add Figure.scalebar to plot a scale bar on maps Add Figure.scalebar to plot a scale bar on maps Dec 10, 2025
Base automatically changed from params/position to main December 11, 2025 01:54
@seisman seisman marked this pull request as ready for review December 11, 2025 11:49
@seisman seisman added the needs review This PR has higher priority and needs review. label Dec 11, 2025
@seisman seisman force-pushed the feature/scalebar branch 4 times, most recently from 0fdd8a3 to c86e8d5 Compare December 18, 2025 09:12
@seisman
Copy link
Member Author

seisman commented Dec 18, 2025

I think this PR is ready for review.

The key points we need to agree on (or explicitly discuss) are:

  • This method wraps the -L option of basemap/coast, so there is no corresponding standalone GMT module. For this reason, I prefer not to add common parameters such as projection, zsize, zscale, frame, or region to this method.
  • Parameter name for +a: align (GMT/GMT.jl) vs label_alignment (PyGMT). An alternative could be label_position.
  • Parameter name for +c: loc (GMT) vs scale_at_lat (GMT.jl) vs scale_position (PyGMT). Possible alternatives include scale_location or scale_lonlat.
  • Parameter name for +u: units (GMT/GMT.jl) vs unit (PyGMT). I think unit is the more appropriate choice.
  • The GMT configuration MAP_SCALE_HEIGHT controls the height of the fancy scalebar. Here it is exposed as a height parameter so users do not need to call pygmt.config.
  • Default position of the scalebar: by default, GMT places it at x0/0, which is often not ideal (see below). A more visually pleasing default is jBL+o0.2c/0.4c (bottom-left with offsets). While the optimal offsets depend on the plot dimensions, this works well for a reasonably sized (~15 cm wide) plot.
gmt begin map png
	gmt basemap -R100/120/30/40 -JM15c -Baf
	gmt basemap -L+w500
	gmt basemap -LjBL+o0.2/0.4+w500
gmt end show
map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Brand new feature needs review This PR has higher priority and needs review.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants