Skip to content

Commit e38b3f9

Browse files
committed
Merge remote-tracking branch 'upstream/master' into mapping/plot3d
2 parents b1ad5e0 + 2bc6828 commit e38b3f9

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

examples/tutorials/plot.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,25 @@
6969
#
7070
# We can also map the colors of the markers to the depths by passing an array to the
7171
# ``color`` argument and providing a colormap name (``cmap``). We can even use the new
72-
# matplotlib colormap "viridis".
72+
# matplotlib colormap "viridis". Here, we first create a continuous colormap
73+
# ranging from the minimum depth to the maximum depth of the earthquakes
74+
# using :func:`pygmt.makecpt`, then set ``cmap=True`` in :func:`pygmt.Figure.plot`
75+
# to use the colormap. At the end of the plot, we also plot a colorbar showing
76+
# the colormap used in the plot.
77+
#
7378

7479
fig = pygmt.Figure()
7580
fig.basemap(region=region, projection="M8i", frame=True)
7681
fig.coast(land="black", water="skyblue")
82+
pygmt.makecpt(cmap="viridis", series=[data.depth_km.min(), data.depth_km.max()])
7783
fig.plot(
7884
x=data.longitude,
7985
y=data.latitude,
8086
sizes=0.02 * 2 ** data.magnitude,
81-
color=data.depth_km / data.depth_km.max(),
82-
cmap="viridis",
87+
color=data.depth_km,
88+
cmap=True,
8389
style="cc",
8490
pen="black",
8591
)
92+
fig.colorbar(frame='af+l"Depth (km)"')
8693
fig.show()
87-
88-
########################################################################################
89-
# .. note::
90-
#
91-
# We normalize the data values given to ``color`` because, by default,
92-
# :meth:`~pygmt.Figure.plot` can only interpret values between 0 and 1. To use the
93-
# actual data values, we would need to create a color palette table (CPT) which
94-
# isn't implemented yet.

0 commit comments

Comments
 (0)