|
17 | 17 | import pandas as pd
|
18 | 18 | import pygmt
|
19 | 19 |
|
20 |
| -# Load sample iris data |
| 20 | +# Load sample iris data and convert 'species' column to categorical dtype |
21 | 21 | 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 |
27 | 22 | df.species = df.species.astype(dtype="category")
|
28 | 23 |
|
29 | 24 | # Use pygmt.info to get region bounds (xmin, xmax, ymin, ymax, zmin, zmax)
|
|
41 | 36 |
|
42 | 37 | # Define a colormap to be used for three categories, define the range of the
|
43 | 38 | # new discrete CPT using series=(lowest_value, highest_value, interval),
|
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)) |
| 39 | +# use color_model="+csetosa,versicolor,virginica" to write the discrete color palette |
| 40 | +# "cubhelix" in categorical format and add the species names as annotations |
| 41 | +pygmt.makecpt( |
| 42 | + cmap="cubhelix", color_model="+csetosa,versicolor,virginica", series=(0, 2, 1) |
| 43 | +) |
47 | 44 |
|
48 | 45 | fig.plot3d(
|
49 | 46 | # Use petal width, sepal length and petal length as x, y and z data input,
|
|
75 | 72 | )
|
76 | 73 |
|
77 | 74 | # Add colorbar legend
|
78 |
| -fig.colorbar() |
| 75 | +fig.colorbar(xshift=3.1) |
79 | 76 |
|
80 | 77 | fig.show()
|
0 commit comments