Skip to content

Commit 28cd791

Browse files
Copilotseismanyvonnefroehlich
authored
Figure.colorbar: Update gallery examples to use new label/unit/annot/tick/grid parameters (#4453)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: seisman <3974108+seisman@users.noreply.github.com> Co-authored-by: Dongdong Tian <seisman.info@gmail.com> Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
1 parent 450446c commit 28cd791

19 files changed

Lines changed: 57 additions & 57 deletions

examples/gallery/3d_plots/3d_bar.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@
5858
perspective=True,
5959
)
6060
fig.colorbar(
61-
frame=["xa1000f500+lElevation", "y+lm"],
61+
annot=1000,
62+
tick=500,
63+
label="Elevation",
64+
unit="m",
6265
position=Position("TR", cstype="inside", offset=1.4),
6366
orientation="vertical",
6467
length=7,

examples/gallery/3d_plots/grdview_surface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ def ackley(x, y):
5757
)
5858

5959
# Add colorbar for gridded data in the Middle Right corner.
60-
fig.colorbar(frame="a2f1", position=Position("MR", cstype="outside"))
60+
fig.colorbar(annot=2, tick=1, position=Position("MR", cstype="outside"))
6161

6262
fig.show()

examples/gallery/basemaps/ternary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@
4343

4444
# Add a colorbar indicating the values given in the fourth column of the input dataset
4545
fig.colorbar(
46-
position=Position("BC", cstype="outside", offset=(0, 1.5)), frame="x+lPermittivity"
46+
position=Position("BC", cstype="outside", offset=(0, 1.5)), label="Permittivity"
4747
)
4848
fig.show()

examples/gallery/embellishments/colorbar.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
55
The :meth:`pygmt.Figure.colorbar` method creates a color scalebar. The colormap is set
66
via the ``cmap`` parameter. A full list of available color palette tables can be found
7-
at :gmt-docs:`reference/cpts.html`. Use the ``frame`` parameter to add labels to the
8-
**x** and **y** axes of the colorbar by appending **+l** followed by the desired text.
9-
To add and adjust the annotations (**a**) and ticks (**f**) append the letter followed
10-
by the desired interval. The placement of the colorbar is set by passing a
11-
:class:`pygmt.params.Position` object to the ``position`` parameter.
7+
at :gmt-docs:`reference/cpts.html`. Use the ``label`` and ``unit`` parameters to set the
8+
labels along the long and short dimensions of the colorbar, respectively. To set the
9+
annotation and tick intervals, use the ``annot`` and ``tick`` parameters. The placement
10+
of the colorbar is set by passing a :class:`pygmt.params.Position` object to the
11+
``position`` parameter.
1212
"""
1313

1414
# %%
@@ -21,22 +21,20 @@
2121
# ============
2222
# Create a colorbar designed for seismic tomography - roma
2323
# Colorbar is placed at Bottom Center (BC) by default if no position is given
24-
# Add quantity and unit as labels ("+l") to the x and y axes
25-
# Add annotations ("+a") in steps of 0.5 and ticks ("+f") in steps of 0.1
26-
fig.colorbar(cmap="SCM/roma", frame=["xa0.5f0.1+lVelocity", "y+lm/s"])
24+
fig.colorbar(cmap="SCM/roma", annot=0.5, tick=0.1, label="Velocity", unit="m/s")
2725

2826
# ============
2927
# Create a colorbar showing the scientific rainbow - batlow
3028
fig.colorbar(
3129
cmap="SCM/batlow",
32-
# A horizontal colorbar positioned at map coordinates (0.3, 8.7), with a
33-
# length of 4 cm and a width of 0.5 cm.
30+
# A horizontal colorbar positioned at map coordinates (0.3, 8.7).
3431
position=Position((0.3, 8.7), cstype="mapcoords"),
3532
length=4,
3633
width=0.5,
3734
orientation="horizontal",
3835
box=True,
39-
frame=["x+lTemperature", "y+l°C"],
36+
label="Temperature",
37+
unit="°C",
4038
scale=100,
4139
)
4240

@@ -45,15 +43,16 @@
4543
fig.colorbar(
4644
cmap="SCM/oleron",
4745
# Colorbar placed at Middle Right (MR) outside the plot bounding box, offset by 1 cm
48-
# horizontally and 0 cm vertically from anchor point, with a length of 7 cm and
49-
# width of 0.5 cm, and a rectangle for NaN values.
50-
# Note that the label 'Elevation' is plotted vertically as a column of characters.
46+
# horizontally and 0 cm vertically from anchor point, with a rectangle for NaN
47+
# values. Note that the label 'Elevation' is plotted vertically as a column of
48+
# characters.
5149
position=Position("MR", cstype="outside", offset=(1, 0)),
5250
length=7,
5351
width=0.5,
5452
nan=True,
5553
label_as_column=True,
56-
frame=["x+lElevation", "y+lm"],
54+
label="Elevation",
55+
unit="m",
5756
scale=10,
5857
)
5958

examples/gallery/embellishments/colorbars_multiple.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
# "R?" means Winkel Tripel projection with map width automatically determined
3030
# from the subplot width.
3131
fig.grdimage(grid=grid_globe, projection="R?", region="g", frame="a")
32-
fig.colorbar(frame=["a4000f2000", "x+lElevation", "y+lm"])
32+
fig.colorbar(annot=4000, tick=2000, label="Elevation", unit="m")
3333
# Activate the second panel so that the colormap created by the makecpt function is
3434
# a panel-level CPT
3535
with fig.set_panel(panel=1):
3636
pygmt.makecpt(cmap="gmt/globe", series=[-6000, 3000])
3737
# "M?" means Mercator projection with map width also automatically determined
3838
# from the subplot width.
3939
fig.grdimage(grid=grid_subset, projection="M?", region=subset_region, frame="a")
40-
fig.colorbar(frame=["a2000f1000", "x+lElevation", "y+lm"])
40+
fig.colorbar(annot=2000, tick=1000, label="Elevation", unit="m")
4141

4242
fig.show()

examples/gallery/histograms/blockm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
fig.coast(land="darkgray", transparency=40)
4040
# Plot original data points
4141
fig.plot(x=data.longitude, y=data.latitude, style="c0.3c", fill="white", pen="1p,black")
42-
fig.colorbar(frame="x+lkm")
42+
fig.colorbar(label="km")
4343

4444
fig.shift_origin(xshift="w+5c")
4545

@@ -56,6 +56,6 @@
5656
)
5757
fig.coast(land="darkgray", transparency=40)
5858
fig.plot(x=data.longitude, y=data.latitude, style="c0.3c", fill="white", pen="1p,black")
59-
fig.colorbar(frame="x+lcount")
59+
fig.colorbar(label="Count")
6060

6161
fig.show()

examples/gallery/images/cross_section.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,15 @@
4242
# Add a colorbar for the elevation
4343
fig.colorbar(
4444
# Place the colorbar inside the plot in the Bottom Right (BR) corner with an offset
45-
# of 0.7 centimeters and 0.3 centimeters in x- or y-directions, respectively;
46-
# move the x-label above the horizontal colorbar.
45+
# of 0.7 centimeters and 0.3 centimeters in x- or y-directions, respectively.
4746
position=Position("BR", offset=(0.7, 0.8)),
4847
length=5,
4948
width=0.3,
5049
orientation="horizontal",
51-
move_text="label",
52-
# Add a box around the colobar, filled in white and a 30 % transparency, with a
53-
# 0.8-point thick, black, outline.
50+
move_text="label", # move the x-label above the horizontal colorbar.
5451
box=Box(pen="0.8p,black", fill="white@30"),
55-
# Add x- and y-labels ("+l")
56-
frame=["x+lElevation", "y+lm"],
52+
label="Elevation",
53+
unit="m",
5754
)
5855

5956
# Plot the survey line

examples/gallery/images/grdclip.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
)
4444
fig.grdimage(grid=grid)
4545
fig.colorbar(
46-
frame=["x+lElevation", "y+lm"],
46+
label="Elevation",
47+
unit="m",
4748
position=Position("MR", cstype="outside", offset=(0.5, 0)),
4849
length=8,
4950
)

examples/gallery/images/grdgradient.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242
position=Position("ML", cstype="outside", offset=(1.4, 0)),
4343
length=7,
4444
width=0.5,
45-
frame=["xa1000f500+lElevation", "y+lm"],
45+
annot=1000,
46+
tick=500,
47+
label="Elevation",
48+
unit="m",
4649
)
4750

4851
# --------------- plotting the hillshade map -----------

examples/gallery/images/grdgradient_shading.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@
7171
length=14,
7272
width=0.4,
7373
orientation="horizontal",
74-
frame="xa2000f500+lElevation (m)",
74+
annot=2000,
75+
tick=500,
76+
label="Elevation (m)",
7577
)
7678

7779
fig.show()

0 commit comments

Comments
 (0)