Skip to content

Commit

Permalink
Add categorical colorbars for plot, plot3d and line colors gallery ex…
Browse files Browse the repository at this point in the history
…amples (GenericMappingTools#1267)

Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
Co-authored-by: Will Schlitzer <schlitzer90@gmail.com>
  • Loading branch information
4 people authored and Josh Sixsmith committed Dec 21, 2022
1 parent 1f567c3 commit 35aeb12
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
23 changes: 15 additions & 8 deletions examples/gallery/3d_plots/scatter3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import pandas as pd
import pygmt

# Load sample iris data, and convert 'species' column to categorical dtype
# 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")
df.species = df.species.astype(dtype="category")

Expand All @@ -36,9 +36,12 @@

# 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="+cSetosa,Versicolor,Virginica" to write the discrete color 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)
)

fig.plot3d(
# Use petal width, sepal length and petal length as x, y and z data input,
Expand All @@ -58,14 +61,18 @@
region=region,
# Set frame parameters
frame=[
"WsNeZ3", # z axis label positioned on 3rd corner
'xafg+l"Petal Width"',
'yafg+l"Sepal Length"',
'zafg+l"Petal Length"',
'WsNeZ3+t"Iris flower data set"', # z axis label positioned on 3rd corner, add title
'xafg+l"Petal Width (cm)"',
'yafg+l"Sepal Length (cm)"',
'zafg+l"Petal Length (cm)"',
],
# Set perspective to azimuth NorthWest (315°), at elevation 25°
perspective=[315, 25],
# Vertical exaggeration factor
zscale=1.5,
)

# Add colorbar legend
fig.colorbar(xshift=3.1)

fig.show()
7 changes: 5 additions & 2 deletions examples/gallery/lines/line_custom_cpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
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="+c0-9" to write the color palette in categorical format and
# add labels (0) to (9) for the colorbar legend
pygmt.makecpt(cmap="batlow", series=[0, 9, 1], color_model="+c0-9")

# Plot 10 lines and set a different z-value for each line
for zvalue in range(0, 10):
y = zvalue * np.sin(x)
fig.plot(x=x, y=y, cmap=True, zvalue=zvalue, pen="thick,+z,-")

# Color bar to show the custom CPT and the associated z-values
fig.colorbar()
fig.show()
11 changes: 6 additions & 5 deletions examples/gallery/symbols/points_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@

# 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="+cAdelie,Chinstrap,Gentoo" to write the discrete color palette
# "inferno" in categorical format and add the species names as annotations for the
# colorbar
pygmt.makecpt(cmap="inferno", series=(0, 2, 1), color_model="+cAdelie,Chinstrap,Gentoo")

fig.plot(
# Use bill length and bill depth as x and y data input, respectively
Expand All @@ -66,7 +67,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()

0 comments on commit 35aeb12

Please sign in to comment.