From 338a79e55d2f6b1a15a83570c9c17f70f0ad333a Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 1 Jun 2020 02:39:30 -0400 Subject: [PATCH] Update the plotting example using the colormap generated by pygmt.makecpt --- examples/tutorials/plot.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/examples/tutorials/plot.py b/examples/tutorials/plot.py index 6752a55b075..f7091687388 100644 --- a/examples/tutorials/plot.py +++ b/examples/tutorials/plot.py @@ -69,26 +69,25 @@ # # We can also map the colors of the markers to the depths by passing an array to the # ``color`` argument and providing a colormap name (``cmap``). We can even use the new -# matplotlib colormap "viridis". +# matplotlib colormap "viridis". Here, we first create a continuous colormap +# ranging from the minimum depth to the maximum depth of the earthquakes +# using :func:`pygmt.makecpt`, then set ``cmap=True`` in :func:`pygmt.Figure.plot` +# to use the colormap. At the end of the plot, we also plot a colorbar showing +# the colormap used in the plot. +# fig = pygmt.Figure() fig.basemap(region=region, projection="M8i", frame=True) fig.coast(land="black", water="skyblue") +pygmt.makecpt(cmap="viridis", series=[data.depth_km.min(), data.depth_km.max()]) fig.plot( x=data.longitude, y=data.latitude, sizes=0.02 * 2 ** data.magnitude, - color=data.depth_km / data.depth_km.max(), - cmap="viridis", + color=data.depth_km, + cmap=True, style="cc", pen="black", ) +fig.colorbar(frame='af+l"Depth (km)"') fig.show() - -######################################################################################## -# .. note:: -# -# We normalize the data values given to ``color`` because, by default, -# :meth:`~pygmt.Figure.plot` can only interpret values between 0 and 1. To use the -# actual data values, we would need to create a color palette table (CPT) which -# isn't implemented yet.