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

Add a gallery example to show coloring of points by categories #1006

Merged
merged 39 commits into from
Mar 12, 2021
Merged
Changes from 2 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 Mar 4, 2021
78c8f31
Merge branch 'master' into gallery-points-cat
michaelgrund Mar 4, 2021
c413c65
Merge branch 'master' into gallery-points-cat
michaelgrund Mar 5, 2021
57b9a38
updated content based on reviews
michaelgrund Mar 5, 2021
87dce83
[format-command] fixes
actions-bot Mar 5, 2021
34bd57b
Update examples/gallery/plot/points-categorial.py
michaelgrund Mar 6, 2021
65966e1
Update examples/gallery/plot/points-categorial.py
michaelgrund Mar 6, 2021
68616b5
Update examples/gallery/plot/points-categorial.py
michaelgrund Mar 6, 2021
96c82f8
Update examples/gallery/plot/points-categorial.py
michaelgrund Mar 6, 2021
61be08c
Merge branch 'master' into gallery-points-cat
michaelgrund Mar 6, 2021
bc7dc1b
updated content based on reviews
michaelgrund Mar 6, 2021
8c3c4f9
updated content based on reviews
michaelgrund Mar 7, 2021
52b23c0
Update examples/gallery/plot/points-categorical.py
michaelgrund Mar 7, 2021
e5c71eb
corrected typo
michaelgrund Mar 7, 2021
cc9756e
modified docstrings
michaelgrund Mar 7, 2021
1974ba5
[format-command] fixes
actions-bot Mar 7, 2021
5434d2f
updates
michaelgrund Mar 7, 2021
e096fc6
Update examples/gallery/plot/points-categorical.py
michaelgrund Mar 9, 2021
b99319f
Update examples/gallery/plot/points-categorical.py
michaelgrund Mar 10, 2021
9a94c90
Update examples/gallery/plot/points-categorical.py
michaelgrund Mar 10, 2021
a7d6db5
Update examples/gallery/plot/points-categorical.py
michaelgrund Mar 10, 2021
571d99b
Update examples/gallery/plot/points-categorical.py
michaelgrund Mar 10, 2021
7c8462c
Update examples/gallery/plot/points-categorical.py
michaelgrund Mar 10, 2021
ee153fd
Update examples/gallery/plot/points-categorical.py
michaelgrund Mar 10, 2021
6a81b1b
Update examples/gallery/plot/points-categorical.py
michaelgrund Mar 10, 2021
7822612
Merge branch 'master' into gallery-points-cat
michaelgrund Mar 10, 2021
439d544
updates based on code review
michaelgrund Mar 10, 2021
8897f7e
Update examples/gallery/plot/points-categorical.py
michaelgrund Mar 10, 2021
0103af4
Update examples/gallery/plot/points-categorical.py
michaelgrund Mar 11, 2021
3d54b39
Update examples/gallery/plot/points-categorical.py
michaelgrund Mar 11, 2021
0164e86
Update examples/gallery/plot/points-categorical.py
michaelgrund Mar 11, 2021
1f47a38
Merge branch 'master' into gallery-points-cat
michaelgrund Mar 11, 2021
544f475
use underscore in filename
michaelgrund Mar 11, 2021
1d01644
Merge branch 'master' into gallery-points-cat
seisman Mar 12, 2021
076ad45
Move to symbols directory
seisman Mar 12, 2021
6c010b0
Update examples/gallery/symbols/points_categorical.py
michaelgrund Mar 12, 2021
a60af87
Update examples/gallery/symbols/points_categorical.py
michaelgrund Mar 12, 2021
a178ae6
Update examples/gallery/symbols/points_categorical.py
michaelgrund Mar 12, 2021
b06b51c
Update examples/gallery/symbols/points_categorical.py
michaelgrund Mar 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions examples/gallery/plot/points-categorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
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 iris data, and convert 'species' column to categorical dtype
df = pd.read_csv("https://github.com/mwaskom/seaborn-data/raw/master/iris.csv")
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
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[["sepal_width", "sepal_length"]], # x and y columns
per_column=True, # report output as a numpy array
)
seisman marked this conversation as resolved.
Show resolved Hide resolved

# 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"Sepal Width"', 'yafg+l"Sepal Length"', "WSen"],
)

# Define colormap to use for three categories
pygmt.makecpt(cmap="inferno", color_model="+c", series=(0, 3, 1))

fig.plot(
x=df.sepal_width, # Use one feature as x data input
y=df.sepal_length, # Use another feature as y data input
sizes=df.petal_width
/ df.petal_length, # Vary each symbol size according to the ratio of the two remaining features
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
color=df.species.cat.codes.astype(int), # Points colored by categorical number code
cmap=True, # Use colormap created by makecpt
no_clip=True, # Do not clip symbols that fall exactly on the map bounds
style="cc", # Use circles as symbols with size in centimeter units
transparency=40, # Set transparency level for all symbols to deal with overplotting
)
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved

fig.show()