Improvement of two gallery examples regarding categorical colormaps#1934
Improvement of two gallery examples regarding categorical colormaps#1934weiji14 merged 5 commits intoGenericMappingTools:mainfrom yvonnefroehlich:improve-examples-categorical-cpt
Conversation
|
💖 Thanks for opening this pull request! 💖 Please make sure you read our contributing guidelines and abide by our code of conduct. A few things to keep in mind:
|
|
I am very sorry for accidentally closing this PR! I reopened it. |
|
Ping @michaelgrund and @weiji14 for reviewing this PR, as they wrote the initial version of the example. |
weiji14
left a comment
There was a problem hiding this comment.
Thanks for taking up this Pull Request @yvonnefroehlich!
I've made a few suggested changes to the documentation wording, which you're welcome to "Commit suggestion" directly, or pool several together using "Add suggestion to batch" before committing. See also https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/incorporating-feedback-in-your-pull-request#applying-a-suggested-change.
| pygmt.makecpt( | ||
| cmap="cubhelix", color_model="+cSetosa,Versicolor,Virginica", series=(0, 2, 1) | ||
| cmap="cubhelix", | ||
| # Use the minum and maximum of the categorical number code |
There was a problem hiding this comment.
| # Use the minum and maximum of the categorical number code | |
| # Use the minimum and maximum of the categorical values (alphabetically sorted) |
There was a problem hiding this comment.
Pandas assigns numbers (in an alphabetical manner) to the individual categories, when converting df.species to the categorical data type:
df.species = df.species.astype(dtype="category")
- Color points by categories: Adelie -> 0, Chinstrap -> 1, Gentoo -> 2
- 3D Scatter plots: setosa -> 0, versicolor -> 1, virginica -> 2
These numbers are used to define the range of the colormap (series of pygmt.makecpt):
series=(df.species.cat.codes.min(), df.species.cat.codes.max(), 1),
Thus, I think we should use here 'categorical number code'. Also because this term is later used in the comment for the color parameter of the pygmt.Figure.plot() or pygmt.Figure.3Dplot() method:
# Points colored by categorical number code
color=df.species.cat.codes.astype(int),
There was a problem hiding this comment.
I'm not that familiar with panda's categorical data type, but looking at the documentation and the functions calls df.species.cat.categories and df.species.cat.codes, I think categories and number code are better.
There was a problem hiding this comment.
Hmm you're right, let's go with categories and number code then. Wasn't aware that pandas actually uses numbers for categorical data!
| # By default pandas assigns the categorical number code in an alphabetical | ||
| # manner to the individual categories. For a non-alphabetical order, you have | ||
| # to adjust the categorical number code. For handling and manipulating | ||
| # categorical data in pandas you may have a look at: | ||
| # https://pandas.pydata.org/docs/user_guide/categorical.html |
There was a problem hiding this comment.
| # By default pandas assigns the categorical number code in an alphabetical | |
| # manner to the individual categories. For a non-alphabetical order, you have | |
| # to adjust the categorical number code. For handling and manipulating | |
| # categorical data in pandas you may have a look at: | |
| # https://pandas.pydata.org/docs/user_guide/categorical.html | |
| # By default, pandas sorts the individual categorical values in an alphabetical | |
| # order. For a non-alphabetical order, you have to manually adjust the list of | |
| # categorical values. For handling and manipulating categorical data in pandas, | |
| # have a look at: | |
| # https://pandas.pydata.org/docs/user_guide/categorical.html |
There was a problem hiding this comment.
There is a typo in the suggested change in line 21: you instead of ou.
There was a problem hiding this comment.
Good spotting, I've corrected the suggested change.
| pygmt.makecpt(cmap="inferno", series=(0, 2, 1), color_model="+cAdelie,Chinstrap,Gentoo") | ||
| pygmt.makecpt( | ||
| cmap="inferno", | ||
| # Use the minum and maximum of the categorical number code |
There was a problem hiding this comment.
| # Use the minum and maximum of the categorical number code | |
| # Use the minimum and maximum of the categorical values (alphabetically sorted) |
I have to say thank you for the nice and welcoming meeting by @meghanrjones and @weiji14 during the EGU conference! 😊 Also thanks to @seisman and @weiji14 for their reviews! |
On second thought, let's keep using 'categories' or `number code' as suggested by @seisman in #1934 (comment) (sorry for the confusion, I was a bit mistaken with pandas categorical data). If @michaelgrund has time, it would be nice to get his input since he wrote this example originally, but if not, we can still continue with the Pull Request. |
No worries and no hurry @weiji14 😉 |
|
I'm fine with all the changes made so far! |
Thanks for your response @michaelgrund ! I updated the text based on the reviews and discussion. |
weiji14
left a comment
There was a problem hiding this comment.
Nice one, thanks again @yvonnefroehlich!
|
🎉🎉🎉 Congrats on merging your first pull request and welcome to the team! 🎉🎉🎉 Please open a new pull request to add yourself to the |
I have to say thank you for allowing and helping me to work on this issue / pull request! 😊
Definitely! 😊 - Likely I learned more than I brought to the project! 😉 |
…enericMappingTools#1934) Clarify that by default the labels for the colorbar must be given in alphabetical order. * add remark regarding categorical number code * use flexible arguments in makecpt * shorten and replace remark regarding categorical number code * fix typos and shorten text based on review

Description of proposed changes
Fixes #1933
Reminders
make formatandmake checkto make sure the code follows the style guide.doc/api/index.rst.Slash Commands
You can write slash commands (
/command) in the first line of a comment to performspecific operations. Supported slash commands are:
/format: automatically format and lint the code/test-gmt-dev: run full tests on the latest GMT development version