Skip to content

Commit eb80fbe

Browse files
committed
update scatter3d example
1 parent e06fd9e commit eb80fbe

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

examples/gallery/3d_plots/scatter3d.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
import pandas as pd
1818
import pygmt
1919

20-
# Load sample iris data, and convert 'species' column to categorical dtype
20+
# Load sample iris data
2121
df = pd.read_csv("https://github.com/mwaskom/seaborn-data/raw/master/iris.csv")
22+
23+
# Extract species names for colorbar legend
24+
species = ",".join(df.species.unique())
25+
26+
# Convert 'species' column to categorical dtype
2227
df.species = df.species.astype(dtype="category")
2328

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

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

4348
fig.plot3d(
4449
# Use petal width, sepal length and petal length as x, y and z data input,
@@ -68,4 +73,8 @@
6873
# Vertical exaggeration factor
6974
zscale=1.5,
7075
)
76+
77+
# Add colorbar legend
78+
fig.colorbar()
79+
7180
fig.show()

0 commit comments

Comments
 (0)