-
Notifications
You must be signed in to change notification settings - Fork 228
Add a gallery example to show coloring of points by categories #1006
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
7ad7f00
Provide gallery example to show coloring of points by categories
michaelgrund 78c8f31
Merge branch 'master' into gallery-points-cat
michaelgrund c413c65
Merge branch 'master' into gallery-points-cat
michaelgrund 57b9a38
updated content based on reviews
michaelgrund 87dce83
[format-command] fixes
actions-bot 34bd57b
Update examples/gallery/plot/points-categorial.py
michaelgrund 65966e1
Update examples/gallery/plot/points-categorial.py
michaelgrund 68616b5
Update examples/gallery/plot/points-categorial.py
michaelgrund 96c82f8
Update examples/gallery/plot/points-categorial.py
michaelgrund 61be08c
Merge branch 'master' into gallery-points-cat
michaelgrund bc7dc1b
updated content based on reviews
michaelgrund 8c3c4f9
updated content based on reviews
michaelgrund 52b23c0
Update examples/gallery/plot/points-categorical.py
michaelgrund e5c71eb
corrected typo
michaelgrund cc9756e
modified docstrings
michaelgrund 1974ba5
[format-command] fixes
actions-bot 5434d2f
updates
michaelgrund e096fc6
Update examples/gallery/plot/points-categorical.py
michaelgrund b99319f
Update examples/gallery/plot/points-categorical.py
michaelgrund 9a94c90
Update examples/gallery/plot/points-categorical.py
michaelgrund a7d6db5
Update examples/gallery/plot/points-categorical.py
michaelgrund 571d99b
Update examples/gallery/plot/points-categorical.py
michaelgrund 7c8462c
Update examples/gallery/plot/points-categorical.py
michaelgrund ee153fd
Update examples/gallery/plot/points-categorical.py
michaelgrund 6a81b1b
Update examples/gallery/plot/points-categorical.py
michaelgrund 7822612
Merge branch 'master' into gallery-points-cat
michaelgrund 439d544
updates based on code review
michaelgrund 8897f7e
Update examples/gallery/plot/points-categorical.py
michaelgrund 0103af4
Update examples/gallery/plot/points-categorical.py
michaelgrund 3d54b39
Update examples/gallery/plot/points-categorical.py
michaelgrund 0164e86
Update examples/gallery/plot/points-categorical.py
michaelgrund 1f47a38
Merge branch 'master' into gallery-points-cat
michaelgrund 544f475
use underscore in filename
michaelgrund 1d01644
Merge branch 'master' into gallery-points-cat
seisman 076ad45
Move to symbols directory
seisman 6c010b0
Update examples/gallery/symbols/points_categorical.py
michaelgrund a60af87
Update examples/gallery/symbols/points_categorical.py
michaelgrund a178ae6
Update examples/gallery/symbols/points_categorical.py
michaelgrund b06b51c
Update examples/gallery/symbols/points_categorical.py
michaelgrund File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" | ||
Color points by categories | ||
--------------------------- | ||
The :meth:`pygmt.Figure.plot` method can be used to plot symbols which are | ||
color-coded by categories. | ||
""" | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import pygmt | ||
|
||
# Load sample penguins data and convert 'species' column to categorical dtype | ||
df = pd.read_csv("https://github.com/mwaskom/seaborn-data/raw/master/penguins.csv") | ||
df["species"] = df.species.astype(dtype="category") | ||
|
||
# Use pygmt.info to get region bounds (xmin, xmax, ymin, ymax) | ||
# The below example will return a numpy array like [2. 4.4 4.3 7.9] | ||
region = pygmt.info( | ||
table=df[["bill_length_mm", "bill_depth_mm"]], # x and y columns | ||
per_column=True, # report output as a numpy array | ||
spacing="3/2", # rounds x and y intervals by 3 and 2 respectively | ||
) | ||
|
||
# Make our 2D categorial scatter plot, coloring each of the 3 species differently | ||
michaelgrund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fig = pygmt.Figure() | ||
|
||
# Generate basemap of 10cm x 10cm size | ||
fig.basemap( | ||
region=region, | ||
projection="X10c/10c", | ||
frame=['xafg+l"Snoot length in mm"', 'yafg+l"Snoot depth in mm"', "WSen"], | ||
michaelgrund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
# Define colormap to use for three categories | ||
pygmt.makecpt(cmap="inferno", color_model="+c", series=(0, 3, 1)) | ||
|
||
fig.plot( | ||
# Use one feature as x data input (snoot length) | ||
michaelgrund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
x=df.bill_length_mm, | ||
# Use another feature as y data input (snoot depth) | ||
michaelgrund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
y=df.bill_depth_mm, | ||
# Vary each symbol size according to another feature (body mass) | ||
sizes=7.5 * 10 ** -5 * df.body_mass_g, | ||
# Points colored by categorical number code | ||
color=df.species.cat.codes.astype(int), | ||
# Use colormap created by makecpt | ||
cmap=True, | ||
# Do not clip symbols that fall close to the map bounds | ||
no_clip=True, | ||
# Use circles as symbols with size in centimeter units | ||
style="cc", | ||
# Set transparency level for all symbols to deal with overplotting | ||
transparency=40, | ||
) | ||
michaelgrund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fig.show() |
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.
Uh oh!
There was an error while loading. Please reload this page.