|
69 | 69 | # |
70 | 70 | # We can also map the colors of the markers to the depths by passing an array to the |
71 | 71 | # ``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 | +# |
73 | 78 |
|
74 | 79 | fig = pygmt.Figure() |
75 | 80 | fig.basemap(region=region, projection="M8i", frame=True) |
76 | 81 | fig.coast(land="black", water="skyblue") |
| 82 | +pygmt.makecpt(cmap="viridis", series=[data.depth_km.min(), data.depth_km.max()]) |
77 | 83 | fig.plot( |
78 | 84 | x=data.longitude, |
79 | 85 | y=data.latitude, |
80 | 86 | 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, |
83 | 89 | style="cc", |
84 | 90 | pen="black", |
85 | 91 | ) |
| 92 | +fig.colorbar(frame='af+l"Depth (km)"') |
86 | 93 | 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