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 an example for plotting multi-parameter symbols #772

Merged
merged 15 commits into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
62 changes: 62 additions & 0 deletions examples/gallery/plot/multi_parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
Multi-parameter symbols
----------------
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved

The :meth:`pygmt.Figure.plot` method can plot individual multi-parameter symbols by passing
the corresponding shortcuts listed below to the ``style`` option. Additionally, we must define
the required parameters in a numpy array (or use an appropriately formatted input file) and pass it
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
to ``data``.

The following symbols are available:

- **e**: ellipses, ``np.array([[lon, lat, direction, major_axis, minor_axis]])``
- **j**: rotated rectangle, ``np.array([[lon, lat, direction, width, height]])``
- **r**: rectangle, ``np.array([[lon, lat, width, height]])``
- **R**: rounded rectangle, ``np.array([[lon, lat, width, height, radius]])``
- **w**: pie wedge, ``np.array([[lon, lat, radius, startdir, stopdir]])``, the last two arguments are
directions given in degrees counter-clockwise from horizontal

Upper-case versions **E**, **J**, and **W** are similar to **e**, **j** and **w** but expect geographic
azimuths and distances.

For more advanced options, see the full option list at :gmt-docs:`plot.html`.
"""

import numpy as np
import pygmt

fig = pygmt.Figure()

fig.basemap(region=[0, 6, 0, 2], projection="x3c", frame=True)

###################
# ELLIPSE
data = np.array([[0.5, 1, 45, 3, 1]])

fig.plot(data=data, style="e", color="orange", pen="2p,black")

###################
# ROTATED RECTANGLE
data = np.array([[1.5, 1, 120, 5, 0.5]])

fig.plot(data=data, style="j", color="red3", pen="2p,black")

###################
# RECTANGLE
data = np.array([[3, 1, 4, 1.5]])

fig.plot(data=data, style="r", color="dodgerblue", pen="2p,black")

###################
# ROUNDED RECTANGLE
data = np.array([[4.5, 1, 1.25, 4, 0.5]])

fig.plot(data=data, style="R", color="seagreen", pen="2p,black")

###################
# PIE WEDGE
data = np.array([[5.5, 1, 2.5, 45, 330]])

fig.plot(data=data, style="w", color="lightgray", pen="2p,black")

fig.show()
37 changes: 37 additions & 0 deletions examples/gallery/plot/rot_rectangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
seisman marked this conversation as resolved.
Show resolved Hide resolved
Rotated rectangle using azimuth
----------------

The :meth:`pygmt.Figure.plot` method can plot rotated rectangles based on a
given azimuth (in degrees east of north) as well as length and width. We can
define the required parameters in a numpy array or use an appropriately
formatted input file. Such representations are often used to e.g. display
results of shear-wave splitting analysis.
"""

import numpy as np
import pygmt

fig = pygmt.Figure()

# generate a basemap around Big Island (Hawai'i) showing coastlines, land, and water
fig.coast(
region=[-156.5, -154.5, 18.5, 20.5],
projection="M6c",
land="grey",
water="lightblue",
shorelines=True,
resolution="f",
frame=["x1", "y1"],
)

# store parameters for rotated rectangle in a numpy
# array (lon, lat, azimuth in degrees east of north, lenght, width)
data = np.array([[-155.533, 19.757, 45, 60, 5]])

# pass the data to the plotting function in addition to the corresponding
# style shortcut for rotated rectangles ("J") as well as set color and pen for
# the rectangle
fig.plot(data=data, style="J", color="red3", pen="black")

fig.show()