Skip to content

Commit a3396c3

Browse files
doc: add example on how to visualize a grid with matplotlib (#50)
1 parent 263d770 commit a3396c3

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def linkcode_resolve(domain, info):
7979
# Intershpinx mapping
8080
intersphinx_mapping = {
8181
"python": ("https://docs.python.org/3", None),
82+
"matplotlib": ("https://matplotlib.org", None),
8283
}
8384

8485
# Add any paths that contain templates here, relative to this directory.

docs/user_guide/concepts_utils/grid.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ These parameters are set during initialization of the grid object:
5252
waves_coming_from=True,
5353
)
5454
55+
.. tip::
56+
The grid values can be visualized e.g. using :mod:`matplotlib` and a polar plot:
57+
58+
.. code:: python
59+
60+
import matplotlib.pyplot as plt
61+
from matplotlib import cm
62+
import numpy as np
63+
64+
65+
f = np.linspace(0., 0.5, 50) # Hz
66+
d = np.linspace(0., 2.0 * np.pi - 1e-8, 50) # rad
67+
v = grid.interpolate(f, d, freq_hz=True, degrees=False)
68+
69+
fig = plt.figure()
70+
ax = fig.add_subplot(111, projection="polar")
71+
ax.contourf(d, f, v, levels=7, cmap=cm.jet)
72+
plt.show()
73+
5574
The grid can be converted to a different wave convention anytime by calling the
5675
:meth:`~waveresponse.Grid.set_wave_convention` method with the desired convention flags.
5776

0 commit comments

Comments
 (0)