Skip to content

Commit 3d64fc1

Browse files
michaelgrundcore-manweiji14seisman
authored
Improve documentation in scatter3d.py gallery example (#1064)
Co-authored-by: Yao Jiayuan <[email protected]> Co-authored-by: Wei Ji <[email protected]> Co-authored-by: Dongdong Tian <[email protected]>
1 parent 69417b4 commit 3d64fc1

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

examples/gallery/3d_plots/scatter3d.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
The :meth:`pygmt.Figure.plot3d` method can be used to plot symbols in 3D.
66
In the example below, we show how the
77
`Iris flower dataset <https://en.wikipedia.org/wiki/Iris_flower_data_set>`__
8-
can be visualized using a perspective 3-dimensional plot. The ``region``
8+
can be visualized using a perspective 3D plot. The ``region``
99
parameter has to include the :math:`x`, :math:`y`, :math:`z` axis limits in the
1010
form of (xmin, xmax, ymin, ymax, zmin, zmax), which can be done automatically
1111
using :meth:`pygmt.info`. To plot the z-axis frame, set ``frame`` as a
@@ -19,35 +19,53 @@
1919

2020
# Load sample iris data, and convert 'species' column to categorical dtype
2121
df = pd.read_csv("https://github.com/mwaskom/seaborn-data/raw/master/iris.csv")
22-
df["species"] = df.species.astype(dtype="category")
22+
df.species = df.species.astype(dtype="category")
2323

2424
# Use pygmt.info to get region bounds (xmin, xmax, ymin, ymax, zmin, zmax)
25-
# The below example will return a numpy array like [0., 3., 4., 8., 1., 7.]
25+
# The below example will return a numpy array like [0.0, 3.0, 4.0, 8.0, 1.0, 7.0]
2626
region = pygmt.info(
2727
table=df[["petal_width", "sepal_length", "petal_length"]], # x, y, z columns
28-
per_column=True, # report output as a numpy array
29-
spacing="1/2/0.5", # rounds x, y and z intervals by 1, 2 and 0.5 respectively
28+
per_column=True, # report the min/max values per column as a numpy array
29+
# round the min/max values of the first three columns to the nearest multiple
30+
# of 1, 2 and 0.5, respectively
31+
spacing=(1, 2, 0.5),
3032
)
3133

32-
# Make our 3D scatter plot, coloring each of the 3 species differently
34+
# Make a 3D scatter plot, coloring each of the 3 species differently
3335
fig = pygmt.Figure()
36+
37+
# Define a colormap to be used for three categories, define the range of the
38+
# 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
3441
pygmt.makecpt(cmap="cubhelix", color_model="+c", series=(0, 3, 1))
42+
3543
fig.plot3d(
44+
# Use petal width, sepal length and petal length as x, y and z data input,
45+
# respectively
3646
x=df.petal_width,
3747
y=df.sepal_length,
3848
z=df.petal_length,
39-
sizes=0.1 * df.sepal_width, # Vary each symbol size according to a data column
40-
color=df.species.cat.codes.astype(int), # Points colored by categorical number code
41-
cmap=True, # Use colormap created by makecpt
42-
region=region, # (xmin, xmax, ymin, ymax, zmin, zmax)
49+
# Vary each symbol size according to another feature (sepal width, scaled by 0.1)
50+
sizes=0.1 * df.sepal_width,
51+
# Use 3D cubes ("u") as symbols, with size in centimeter units ("c")
52+
style="uc",
53+
# Points colored by categorical number code
54+
color=df.species.cat.codes.astype(int),
55+
# Use colormap created by makecpt
56+
cmap=True,
57+
# Set map dimensions (xmin, xmax, ymin, ymax, zmin, zmax)
58+
region=region,
59+
# Set frame parameters
4360
frame=[
4461
"WsNeZ3", # z axis label positioned on 3rd corner
4562
'xafg+l"Petal Width"',
4663
'yafg+l"Sepal Length"',
4764
'zafg+l"Petal Length"',
4865
],
49-
style="uc", # 3D cUbe, with size in centimeter units
50-
perspective=[315, 25], # Azimuth NorthWest (315°), at elevation 25°
51-
zscale=1.5, # Vertical exaggeration factor
66+
# Set perspective to azimuth NorthWest (315°), at elevation 25°
67+
perspective=[315, 25],
68+
# Vertical exaggeration factor
69+
zscale=1.5,
5270
)
5371
fig.show()

0 commit comments

Comments
 (0)