Skip to content

Commit 16fc565

Browse files
yvonnefroehlichactions-botwillschlitzerseismanmichaelgrund
authored
Add colorbars to plots of gallery and tutorial examples (#2190)
* Add code for colorbar in 'contour_map.py' * Add text for colorbar in 'contour_map.py' * Add code for colorbar in 'grdview_surface.py' * Add comments for colorbar in 'grdview_surface.py' * Add gridlines in 'grdview_surface.py' Co-authored-by: actions-bot <[email protected]> Co-authored-by: Will Schlitzer <[email protected]> Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: Michael Grund <[email protected]>
1 parent c833f88 commit 16fc565

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

examples/gallery/3d_plots/grdview_surface.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ def ackley(x, y):
3939
fig = pygmt.Figure()
4040

4141
# Plot grid as a 3-D surface
42-
SCALE = 0.5 # in centimeter
42+
SCALE = 0.5 # in centimeters
4343
fig.grdview(
4444
data,
45-
frame=["a5f1", "za5f1"],
45+
# Set annotations and gridlines in steps of five, and
46+
# tick marks in steps of one
47+
frame=["a5f1g5", "za5f1g5"],
4648
projection=f"x{SCALE}c",
4749
zscale=f"{SCALE}c",
4850
surftype="s",
@@ -51,4 +53,10 @@ def ackley(x, y):
5153
shading="+a45",
5254
)
5355

56+
# Add colorbar for gridded data
57+
fig.colorbar(
58+
frame="a2f1", # Set annotations in steps of two, tick marks in steps of one
59+
position="JRM", # Place colorbar at position Right Middle
60+
)
61+
5462
fig.show()

examples/tutorials/advanced/contour_map.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@
8787
# :meth:`pygmt.Figure.grdcontour` to keep the contour lines visible on the
8888
# final map. If the ``projection`` parameter is specified in the
8989
# :meth:`pygmt.Figure.grdimage` method, it does not need to be repeated in the
90-
# :meth:`pygmt.Figure.grdcontour` method.
90+
# :meth:`pygmt.Figure.grdcontour` method. Finally, a colorbar is added using
91+
# the :meth:`pygmt.Figure.colorbar` method.
9192

9293
fig = pygmt.Figure()
9394
fig.grdimage(
@@ -102,4 +103,5 @@
102103
grid=grid,
103104
limit=[-4000, -2000],
104105
)
106+
fig.colorbar(frame=["x+lelevation", "y+lm"])
105107
fig.show()

0 commit comments

Comments
 (0)