Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a gallery example of setting line colors with a custom CPT #774

Merged
merged 5 commits into from
Dec 30, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add line-custom-cpt.py
  • Loading branch information
willschlitzer committed Dec 29, 2020
commit deaa4f5e03a23a2dbbed09abffbafb04ce667cd8
31 changes: 31 additions & 0 deletions examples/gallery/line/line-custom-cpt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Line colors with a custom CPT
-----------------------------

The color of the lines made by :meth:`pygmt.Figure.plot` can be set according to a
custom CPT and assigned with the *pen* argument.
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved

The custom CPT can be used by setting the plot command's `cmap` argument to *True*. The
`zvalue` argument sets the z-value (color) to be used from the custom CPT, and the line
color is set as the z-value by using **+z** when setting the `pen` color.
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved

"""

import numpy as np
import pygmt

# Create a custom CPT with the batlow CPT and 10 discrete z-values (colors)
pygmt.makecpt(cmap="batlow", series=[0, 10, 1])
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
# Create a list of values between 20 and 30 with at 0.2 intervals
x = np.arange(start=20, stop=30, step=0.2)

fig = pygmt.Figure()
fig.basemap(frame=["WSne", "af"], region=[20, 30, -10, 10])

# Plot 10 lines and set a different z-value for each line
for zvalue in range(0, 10):
y = zvalue * np.sin(x)
fig.plot(x=x, y=y, cmap=True, zvalue=zvalue, pen="thick,+z,-")
# Color bar to show the custom CPT and the associated z-values
fig.colorbar()
fig.show()