-
Notifications
You must be signed in to change notification settings - Fork 224
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
Improvement of two gallery examples regarding categorical colormaps #1934
Improvement of two gallery examples regarding categorical colormaps #1934
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. |
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.
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.
# palette "cubhelix" in categorical format and add the species names as | ||
# annotations for the colorbar | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typo in the suggested change in line 21: you
instead of ou
.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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. |
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.
Looks great!
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.
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 format
andmake check
to 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