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 — Add Figure.scalebar to plot a scale bar on maps by seisman · Pull Request #4015 · GenericMappingTools/pygmt

Conversation

@seisman

@seisman seisman commented Jul 26, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

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

Related to #4268

TODO in separate PRs

  • Update gallery examples using the new scalebar method
  • Deprecate map_scale in Figure.coast/Figure.basemap Figure.basemap/Figure.coast: Recommend to use the Figure.scalebar method to add a scalebar #4337
  • Update the example in the paper Figure 3: Update with the Figure.scalebar method pygmt-paper-figures#28

Sorry, something went wrong.

Uh oh!

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

All reactions
@seisman seisman mentioned this pull request Jul 26, 2025
POC: Implement the new alias system, general parameter classes and some refactors #3238
Closed
Base automatically changed from AliasSystem/aliassystem to main July 29, 2025 04:09
@seisman
seisman force-pushed the feature/scalebar branch 3 times, most recently from 7a276b0 to ec9b800 Compare July 29, 2025 06:57
@seisman seisman added the feature Brand new feature label Aug 10, 2025
@seisman seisman added this to the 0.18.0 milestone Sep 18, 2025
@seisman seisman mentioned this pull request Oct 16, 2025
Add the Position class for GMT embellishment placement #4168
Closed
9 tasks done
@seisman seisman added this to PyGMT paper Nov 7, 2025
@seisman
seisman force-pushed the feature/scalebar branch from 8acb461 to 14283bd Compare November 26, 2025 07:32
This was referenced Dec 4, 2025
Figure.basemap: Plot base maps and frames #4239
Closed
Figure.coast: Plot continents, countries, shorelines, rivers, and borders #4240
Open
@seisman
seisman changed the base branch from main to params/position December 6, 2025 16:33
@seisman seisman mentioned this pull request Dec 7, 2025
Tracking the status of the examples included in the paper GenericMappingTools/pygmt-paper-figures#14
Closed
18 of 19 tasks
@seisman
seisman force-pushed the feature/scalebar branch from 2a0ea6b to 17d8427 Compare December 9, 2025 16:12
@github-actions

github-actions Bot commented Dec 9, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

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 cc40c8f

All reactions

Sorry, something went wrong.

Uh oh!

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

@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 added this to PyGMT: Wrapping GMT modules Dec 11, 2025
@seisman seisman removed this from PyGMT: Wrapping GMT modules Dec 11, 2025
seisman
seisman commented Dec 11, 2025
View reviewed changes
Comment thread pygmt/src/scalebar.py Resolved

Uh oh!

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

Comment thread pygmt/src/scalebar.py
length: float | str | None = None,
scale_position: float | Sequence[float] | bool = False,
label: str | bool = False,
label_alignment: Literal["left", "right", "top", "bottom"] | None = None,

@seisman seisman Dec 11, 2025

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.

GMT and GMT.jl use align, currently PyGMT uses label_alignment, but maybe label_position?

Sorry, something went wrong.

Uh oh!

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

All reactions

@yvonnefroehlich yvonnefroehlich Jan 20, 2026

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.

I feel label_position is more consisten, as we have nan_position for Figure.colorbar. And it is a bit shorter.

Sorry, something went wrong.

Uh oh!

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

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

Uh oh!

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

@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 mentioned this pull request Dec 11, 2025
Figure.scalebar: Add a scale bar on maps #4268
Closed
19 of 33 tasks
@seisman
seisman force-pushed the feature/scalebar branch 4 times, most recently from 0fdd8a3 to c86e8d5 Compare December 18, 2025 09:12
@seisman

seisman commented Dec 18, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member Author

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. [Changed to scale_at following ChatGPT's recommendation]
  • 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
All reactions

Sorry, something went wrong.

Uh oh!

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

Copilot AI reviewed Jan 17, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

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

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

Uh oh!

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

@seisman
Update pygmt/src/scalebar.py
c192853
Co-authored-by: Copilot <[email protected]>
yvonnefroehlich
yvonnefroehlich reviewed Jan 17, 2026
View reviewed changes
Comment thread pygmt/src/scalebar.py Resolved

Uh oh!

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

Comment thread pygmt/src/scalebar.py Outdated
length: float | str,
height: float | str | None = None,
position: Position | Sequence[float | str] | AnchorCode | None = None,
scale_at: float | Sequence[float] | bool = False,

@yvonnefroehlich yvonnefroehlich Jan 17, 2026

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.

Hm. I do not really like this name.

Sorry, something went wrong.

Uh oh!

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

All reactions

@seisman seisman Jan 17, 2026

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.

GMT uses loc, GMT.jl uses scale_at_lat.

An alternative name may be scale_loc?

Sorry, something went wrong.

Uh oh!

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

All reactions

@yvonnefroehlich yvonnefroehlich Jan 18, 2026

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.

Not so easy finding a good name here. I was thinking about something in the direction of

  • reference_coords: a bit long
  • reference_lat, scale_lat: partly also the longitude is given

Maybe location is enough, as "scale" is already contained in the method name "scalebar"?

Sorry, something went wrong.

Uh oh!

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

All reactions

@seisman seisman Jan 18, 2026

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.

I feel users may be confused by position and location

Sorry, something went wrong.

Uh oh!

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

All reactions

@yvonnefroehlich yvonnefroehlich Jan 18, 2026

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.

Hm, this is something I was also a bit unsure about. Maybe there are ideas or preferences by @weiji14 and @michaelgrund?

Sorry, something went wrong.

Uh oh!

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

All reactions

@yvonnefroehlich yvonnefroehlich Jan 19, 2026

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.

I think scale_loc is the best name we have so far:

  • not too long
  • location can be all, latitude, longitude, middle of the map, reference point
  • "loc" as a shortcut for "location" should be OK
  • the leading "scale" should reduce a potential confusion with position

Sorry, something went wrong.

Uh oh!

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

All reactions

@seisman seisman Jan 20, 2026

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.

OK. Done in 0561ba4.

Sorry, something went wrong.

Uh oh!

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

All reactions
@seisman @yvonnefroehlich
Fix docstrings
777cd3a
Co-authored-by: Yvonne Fröhlich <[email protected]>
yvonnefroehlich
yvonnefroehlich reviewed Jan 17, 2026
View reviewed changes
Comment thread pygmt/src/scalebar.py Resolved

Uh oh!

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

@seisman @yvonnefroehlich
Improve docstrings for fancy
188367a
Co-authored-by: Yvonne Fröhlich <[email protected]>
yvonnefroehlich
yvonnefroehlich reviewed Jan 17, 2026
View reviewed changes
Comment thread pygmt/src/scalebar.py Resolved

Uh oh!

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

Comment thread pygmt/src/scalebar.py Resolved

Uh oh!

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

Comment thread pygmt/src/scalebar.py Resolved

Uh oh!

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

Comment thread pygmt/src/scalebar.py Resolved

Uh oh!

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

@seisman @yvonnefroehlich
Apply suggestions from code review
c7b86c9
Co-authored-by: Yvonne Fröhlich <[email protected]>
yvonnefroehlich
yvonnefroehlich reviewed Jan 17, 2026
View reviewed changes
Comment thread pygmt/src/scalebar.py Resolved

Uh oh!

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

@seisman @yvonnefroehlich
Update pygmt/src/scalebar.py
cc15a31
Co-authored-by: Yvonne Fröhlich <[email protected]>
@seisman seisman mentioned this pull request Jan 18, 2026
Add a separate documentation for supported plot and distance units #4359
Merged
seisman added 5 commits January 18, 2026 14:26
@seisman
Merge branch 'main' into feature/scalebar
1c8c5c1
@seisman
Merge branch 'main' into feature/scalebar
f44f784
@seisman
Simplify _parse_position
971d147
@seisman
Merge branch 'main' into feature/scalebar
e2c1254
@seisman
Rename scale_at to scale_loc
0561ba4
@seisman

seisman commented Jan 20, 2026

Copy link
Copy Markdown
Member Author

I'll merge this PR in 24 hours if no further comments.

All reactions

Sorry, something went wrong.

Uh oh!

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

@yvonnefroehlich

yvonnefroehlich commented Jan 20, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

The gallery example (https://www.pygmt.org/dev/gallery/embellishments/scalebar.html) is updated in a separate PR, like for Figure.colorbar?

All reactions

Sorry, something went wrong.

Uh oh!

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

@seisman

seisman commented Jan 20, 2026

Copy link
Copy Markdown
Member Author

The gallery example (https://www.pygmt.org/dev/gallery/embellishments/scalebar.html) is updated in a separate PR, like for Figure.colorbar?

Yes, too keep this PR small

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

Sorry, something went wrong.

Uh oh!

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

yvonnefroehlich
yvonnefroehlich reviewed Jan 20, 2026
View reviewed changes
Comment thread pygmt/src/scalebar.py Resolved

Uh oh!

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

Comment thread pygmt/src/scalebar.py
length: float | str | None = None,
scale_position: float | Sequence[float] | bool = False,
label: str | bool = False,
label_alignment: Literal["left", "right", "top", "bottom"] | None = None,

@yvonnefroehlich yvonnefroehlich Jan 20, 2026

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.

I feel label_position is more consisten, as we have nan_position for Figure.colorbar. And it is a bit shorter.

Sorry, something went wrong.

Uh oh!

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

All reactions
yvonnefroehlich
yvonnefroehlich approved these changes Jan 20, 2026
View reviewed changes

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

Made two more comments.
Besides this, this PR looks good to me.

Sorry, something went wrong.

Uh oh!

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

All reactions
@seisman @yvonnefroehlich
Update pygmt/src/scalebar.py
cc40c8f
Co-authored-by: Yvonne Fröhlich <[email protected]>
@seisman

seisman commented Jan 21, 2026

Copy link
Copy Markdown
Member Author

I feel label_position is more consisten, as we have nan_position for Figure.colorbar. And it is a bit shorter.

label_alignment is already used in Figure.wiggle. So I prefer to keep it consistent.

All reactions

Sorry, something went wrong.

Uh oh!

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

@seisman

seisman commented Jan 21, 2026

Copy link
Copy Markdown
Member Author

I'm merging this PR. We can still change the parameter names before releasing v0.19.0.

All reactions

Sorry, something went wrong.

Uh oh!

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

@seisman
seisman merged commit 613bdc1 into main Jan 21, 2026
27 of 31 checks passed

Uh oh!

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

@seisman
seisman deleted the feature/scalebar branch January 21, 2026 02:48
@github-project-automation github-project-automation Bot moved this to Done in PyGMT paper Jan 21, 2026
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Jan 21, 2026
@yvonnefroehlich

yvonnefroehlich commented Jan 21, 2026

Copy link
Copy Markdown
Member

I feel label_position is more consisten, as we have nan_position for Figure.colorbar. And it is a bit shorter.

label_alignment is already used in Figure.wiggle. So I prefer to keep it consistent.

OK, consistency with Figure.wiggle is important.

All reactions

Sorry, something went wrong.

Uh oh!

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

@seisman

seisman commented Jan 23, 2026

Copy link
Copy Markdown
Member Author
  • Update gallery examples using the new scalebar method

@yvonnefroehlich Please let me know if you're interested in updating the gallery example https://www.pygmt.org/dev/gallery/embellishments/scalebar.html.

All reactions

Sorry, something went wrong.

Uh oh!

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

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

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@yvonnefroehlich yvonnefroehlich yvonnefroehlich approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

feature Brand new feature

Projects

No open projects
PyGMT paper
Status: Done

Milestone

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

@seisman @yvonnefroehlich
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 01402775 — 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.