Skip to content

Commit 35aeb12

Browse files
michaelgrundseismanweiji14willschlitzer
authored andcommitted
Add categorical colorbars for plot, plot3d and line colors gallery examples (GenericMappingTools#1267)
Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: Wei Ji <[email protected]> Co-authored-by: Will Schlitzer <[email protected]>
1 parent 1f567c3 commit 35aeb12

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

examples/gallery/3d_plots/scatter3d.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
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 and convert 'species' column to categorical dtype
2121
df = pd.read_csv("https://github.com/mwaskom/seaborn-data/raw/master/iris.csv")
2222
df.species = df.species.astype(dtype="category")
2323

@@ -36,9 +36,12 @@
3636

3737
# Define a colormap to be used for three categories, define the range of the
3838
# 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))
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 for the
41+
# colorbar
42+
pygmt.makecpt(
43+
cmap="cubhelix", color_model="+cSetosa,Versicolor,Virginica", series=(0, 2, 1)
44+
)
4245

4346
fig.plot3d(
4447
# Use petal width, sepal length and petal length as x, y and z data input,
@@ -58,14 +61,18 @@
5861
region=region,
5962
# Set frame parameters
6063
frame=[
61-
"WsNeZ3", # z axis label positioned on 3rd corner
62-
'xafg+l"Petal Width"',
63-
'yafg+l"Sepal Length"',
64-
'zafg+l"Petal Length"',
64+
'WsNeZ3+t"Iris flower data set"', # z axis label positioned on 3rd corner, add title
65+
'xafg+l"Petal Width (cm)"',
66+
'yafg+l"Sepal Length (cm)"',
67+
'zafg+l"Petal Length (cm)"',
6568
],
6669
# Set perspective to azimuth NorthWest (315°), at elevation 25°
6770
perspective=[315, 25],
6871
# Vertical exaggeration factor
6972
zscale=1.5,
7073
)
74+
75+
# Add colorbar legend
76+
fig.colorbar(xshift=3.1)
77+
7178
fig.show()

examples/gallery/lines/line_custom_cpt.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@
2121
fig = pygmt.Figure()
2222
fig.basemap(frame=["WSne", "af"], region=[20, 30, -10, 10])
2323

24-
# Create a custom CPT with the batlow CPT and 10 discrete z-values (colors)
25-
pygmt.makecpt(cmap="batlow", series=[0, 10, 1])
24+
# Create a custom CPT with the batlow CPT and 10 discrete z-values (colors),
25+
# use color_model="+c0-9" to write the color palette in categorical format and
26+
# add labels (0) to (9) for the colorbar legend
27+
pygmt.makecpt(cmap="batlow", series=[0, 9, 1], color_model="+c0-9")
2628

2729
# Plot 10 lines and set a different z-value for each line
2830
for zvalue in range(0, 10):
2931
y = zvalue * np.sin(x)
3032
fig.plot(x=x, y=y, cmap=True, zvalue=zvalue, pen="thick,+z,-")
33+
3134
# Color bar to show the custom CPT and the associated z-values
3235
fig.colorbar()
3336
fig.show()

examples/gallery/symbols/points_categorical.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@
4444

4545
# Define a colormap to be used for three categories, define the range of the
4646
# new discrete CPT using series=(lowest_value, highest_value, interval),
47-
# use color_model="+c" to write the discrete color palette "inferno" in
48-
# categorical format
49-
pygmt.makecpt(cmap="inferno", series=(0, 3, 1), color_model="+c")
47+
# use color_model="+cAdelie,Chinstrap,Gentoo" to write the discrete color palette
48+
# "inferno" in categorical format and add the species names as annotations for the
49+
# colorbar
50+
pygmt.makecpt(cmap="inferno", series=(0, 2, 1), color_model="+cAdelie,Chinstrap,Gentoo")
5051

5152
fig.plot(
5253
# Use bill length and bill depth as x and y data input, respectively
@@ -66,7 +67,7 @@
6667
transparency=40,
6768
)
6869

69-
# A colorbar displaying the different penguin species types will be added
70-
# once GMT 6.2.0 is released.
70+
# Add colorbar legend
71+
fig.colorbar()
7172

7273
fig.show()

0 commit comments

Comments
 (0)