Fix reverse cmap issues - #20
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies the plot_grid function in pygmt_helper/plotting.py to swap the background and foreground limit colors when reverse_cmap is enabled. The review feedback suggests simplifying this conditional assignment to make it more idiomatic and concise using tuple slicing.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
This PR fixes how out-of-range colormap “limit colors” are assigned in plot_grid when reverse_cmap=False, addressing Issue #19 where the background/foreground colors were effectively reversed in the non-reversed colormap case.
Changes:
- Add conditional logic so
COLOR_BACKGROUND/COLOR_FOREGROUNDare assigned based onreverse_cmap, instead of always using the same order. - Document (inline) why the swap is needed when
reverse_cmapis enabled.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Set the background & foreground colour for the colormap | ||
| pygmt.config( | ||
| COLOR_BACKGROUND=cmap_limit_colors[1], COLOR_FOREGROUND=cmap_limit_colors[0] | ||
| ) | ||
| # When reverse_cmap is True, the cmap is reversed so the limit colours | ||
| # must be swapped to stay correct for values below/above the range. | ||
| if reverse_cmap: | ||
| bg_color, fg_color = cmap_limit_colors[1], cmap_limit_colors[0] | ||
| else: | ||
| bg_color, fg_color = cmap_limit_colors[0], cmap_limit_colors[1] | ||
| pygmt.config(COLOR_BACKGROUND=bg_color, COLOR_FOREGROUND=fg_color) |
Fixes an issue with the plot grid functionality when reverse cmap is disabled: the limit colours are incorrectly assigned. Fixes #19