Skip to content
17 changes: 13 additions & 4 deletions examples/gallery/3d_plots/scatter3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
import pandas as pd
import pygmt

# Load sample iris data, and convert 'species' column to categorical dtype
# Load sample iris data
df = pd.read_csv("https://github.com/mwaskom/seaborn-data/raw/master/iris.csv")

# Extract species names for colorbar legend
species = ",".join(df.species.unique())

# Convert 'species' column to categorical dtype
df.species = df.species.astype(dtype="category")

# Use pygmt.info to get region bounds (xmin, xmax, ymin, ymax, zmin, zmax)
Expand All @@ -36,9 +41,9 @@

# Define a colormap to be used for three categories, define the range of the
# new discrete CPT using series=(lowest_value, highest_value, interval),
# use color_model="+c" to write the discrete color palette "cubhelix" in
# categorical format
pygmt.makecpt(cmap="cubhelix", color_model="+c", series=(0, 3, 1))
# use color_model="+c" + species to write the discrete color palette "cubhelix" in
# categorical format and add the species names extracted above as annotations
pygmt.makecpt(cmap="cubhelix", color_model="+c" + species, series=(0, 2, 1))

fig.plot3d(
# Use petal width, sepal length and petal length as x, y and z data input,
Expand Down Expand Up @@ -68,4 +73,8 @@
# Vertical exaggeration factor
zscale=1.5,
)

# Add colorbar legend
fig.colorbar()

fig.show()
8 changes: 6 additions & 2 deletions examples/gallery/lines/line_custom_cpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
fig = pygmt.Figure()
fig.basemap(frame=["WSne", "af"], region=[20, 30, -10, 10])

# Create a custom CPT with the batlow CPT and 10 discrete z-values (colors)
pygmt.makecpt(cmap="batlow", series=[0, 10, 1])
# Create a custom CPT with the batlow CPT and 10 discrete z-values (colors),
# use color_model="+c" + ','.join(map(str, range(1,11))) to write the color
# palette in categorical format and add labels (1) to (10) for the colorbar legend
pygmt.makecpt(
cmap="batlow", series=[0, 9, 1], color_model="+c" + ",".join(map(str, range(1, 11)))
)

# Plot 10 lines and set a different z-value for each line
for zvalue in range(0, 10):
Expand Down
17 changes: 11 additions & 6 deletions examples/gallery/symbols/points_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
import pandas as pd
import pygmt

# Load sample penguins data and convert 'species' column to categorical dtype
# Load sample penguins data
df = pd.read_csv("https://github.com/mwaskom/seaborn-data/raw/master/penguins.csv")

# Extract species names for colorbar legend
species = ",".join(df.species.unique())

# Convert 'species' column to categorical dtype
df.species = df.species.astype(dtype="category")

# Use pygmt.info to get region bounds (xmin, xmax, ymin, ymax)
Expand Down Expand Up @@ -44,9 +49,9 @@

# Define a colormap to be used for three categories, define the range of the
# new discrete CPT using series=(lowest_value, highest_value, interval),
# use color_model="+c" to write the discrete color palette "inferno" in
# categorical format
pygmt.makecpt(cmap="inferno", series=(0, 3, 1), color_model="+c")
# use color_model="+c" + species to write the discrete color palette "inferno" in
# categorical format and add the species names extracted above as annotations
pygmt.makecpt(cmap="inferno", series=(0, 2, 1), color_model="+c" + species)

fig.plot(
# Use bill length and bill depth as x and y data input, respectively
Expand All @@ -66,7 +71,7 @@
transparency=40,
)

# A colorbar displaying the different penguin species types will be added
# once GMT 6.2.0 is released.
# Add colorbar legend
fig.colorbar()

fig.show()