Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap colorbar #332

Merged
merged 8 commits into from
Nov 1, 2019
Merged

Conversation

weiji14
Copy link
Member

@weiji14 weiji14 commented Oct 5, 2019

Wrapping the colorbar function!

See also Julia implementation at https://www.generic-mapping-tools.org/GMT.jl/latest/#GMT.colorbar.

Description of proposed changes

Example code:

import pygmt
fig = pygmt.Figure()
fig.basemap(region=[2, 4, 6, 8], projection="t0/2c", frame=True)
fig.colorbar(cmap="rainbow", position="jTC+w2c")
fig.show()

Colorbar teaser

Parameters/Aliases to wrap:

  • B = frame (or axis in GMT.jl)
  • C = cmap
  • D = position
  • F = box
  • G = truncate
  • I = intensity (or shade in GMT.jl)
  • J = projection
  • L = equal
  • M = monochrome
  • N = dpi
  • Q = log
  • R = region
  • S = nolines
  • U = stamp
  • V = verbose
  • W = zscale
  • Z = zfile
    ...

Fixes #109, part of #231

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 adding new functionality, add an example to docstrings or tutorials.

Initial commit for wrapping the colorbar function raised first at #109 but also #231, to be implemented under base_plotting.py alongside the other mapping related stuff. Original GMT `colorbar` documentation can be found at https://docs.generic-mapping-tools.org/latest/colorbar.html.

Storing sample test cases under test_colorbar.py. Current implementation has an alias for position (D) which is arguably the most important one. and the one we've focused writing the tests for. Also wrapped around common aliases region (R), projection (J), frame (B) and cmap (C).
@weiji14 weiji14 added this to the 0.1.0 milestone Oct 5, 2019
@weiji14 weiji14 self-assigned this Oct 5, 2019
Including tests for controlling how the border around the color scalebar is styled.
Included one test for checking the truncation works to a min/max range. Also made sure region (R) is parsed as a slash separated sequence string.
Include one test for 0.1x scale. Also added docs for truncate (G) that was missing in the last commit.
Created a gallery example for `colorbar` illustrating some scientific colourmaps and ways of positioning the colorbar inside the map frame. Changed title of this gallery section to be a more generic "Plotting map items". Also corrected lat/lon to lon/lat in the docstring of one of the tests.
@weiji14 weiji14 marked this pull request as ready for review October 25, 2019 23:07
@weiji14 weiji14 requested a review from a team October 25, 2019 23:08
@weiji14
Copy link
Member Author

weiji14 commented Oct 25, 2019

Alright, colorbar is ready for review! I've made a new gallery example you all can preview at https://pygmt-git-fork-weiji14-mapping-colorbar.gmt.now.sh/gallery/plot/colorbar.html, and there's plenty of tests covering various ways to set the position and styling. Sneakpeek below:

Colorbar gallery example

@weiji14
Copy link
Member Author

weiji14 commented Oct 31, 2019

@liamtoney, do you mind reviewing this colorbar implementation if you have time? It's actually pretty similar to the legend wrapper in terms of having a position and box argument.

Copy link
Member

@liamtoney liamtoney left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thorough tests — nice.

cmap="oleron",
position="jTC+w6c/1c+h", # justified inside map frame (j) at Top Center (TC)
box=True,
frame=["+Loleron", "xaf", "y+lm"],
Copy link
Member

Choose a reason for hiding this comment

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

Have we documented how the argument

frame=["+Loleron", "xaf", "y+lm"]

is equivalent to

-B+Loleron -Bxaf -By+lm

(i.e. use a list to replicate repeated flags) somewhere? I think it could be a good item to add to the Note for experienced GMT users in the docs and can do so if desired.

Copy link
Member Author

Choose a reason for hiding this comment

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

Funny you said that, I only discovered that recently too at #325 (comment) but didn't know where best to put it in the docs.

I think it could be a good item to add to the Note for experienced GMT users in the docs and can do so if desired.

Yep, go for it!

@weiji14 weiji14 merged commit af81c33 into GenericMappingTools:master Nov 1, 2019
@weiji14 weiji14 deleted the mapping/colorbar branch November 1, 2019 07:45
@weiji14
Copy link
Member Author

weiji14 commented Nov 1, 2019

Cheers for reviewing this @liamtoney! I'll take a look at your legend gallery example next. There might be some merge conflicts with this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

how to build a colorbar
2 participants