oceans.plotting

class oceans.plotting.EditPoints(fig, ax, points, verbose=False)[source]

Bases: object

Edit points on a graph with the mouse. Handles only one set of points.

Key-bindings:

‘t’ toggle on and off. (When on, you can move, delete, or add points.) ‘d’ delete the point. ‘i’ insert a point.

Examples

>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots(figsize=(6, 6))
>>> theta = np.arange(0, 2 * np.pi, 0.1)
>>> r = 1.5
>>> xs = r * np.cos(theta)
>>> ys = r * np.sin(theta)
>>> points = ax.plot(xs, ys, "ko")
>>> p = EditPoints(fig, ax, points[0], verbose=True)
>>> _ = ax.set_title("Click and drag a point to move it")
>>> _ = ax.axis([-2, 2, -2, 2])

Based on https://matplotlib.org/examples/event_handling/poly_editor.html

button_press_callback(event)[source]

Whenever a mouse button is pressed.

button_release_callback(event)[source]

Whenever a mouse button is released.

draw_callback(event)[source]
epsilon = 5
get_ind_under_point(event)[source]

Get the index of the point under mouse if within epsilon tolerance.

key_press_callback(event)[source]

Whenever a key is pressed.

motion_notify_callback(event)[source]

On mouse movement.

points_changed(points)[source]

This method is called whenever the points object is called.

showpoint = True
oceans.plotting.compass(u, v, **arrowprops)[source]

Compass draws a graph that displays the vectors with components u and v as arrows from the origin.

Examples

>>> import numpy as np
>>> u = [+0, -0.5, -0.50, +0.90]
>>> v = [+1, +0.5, -0.45, -0.85]
>>> fig, ax = compass(u, v)
oceans.plotting.get_pointsxy(points)[source]

Return x, y of the given point object.

oceans.plotting.landmask(M, color='0.8')[source]

Plot land mask.

Based on trondkristiansen mpl_util.py.

oceans.plotting.level_colormap(levels, cmap=None)[source]

Make a colormap based on an increasing sequence of levels.

Based on trondkristiansen.com mpl_util.py.

oceans.plotting.plot_spectrum(data, fs)[source]

Plots a Single-Sided Amplitude Spectrum of y(t).

oceans.plotting.stick_plot(time, u, v, **kw)[source]
Parameters:
  • time (list/arrays of datetime objects) –

  • u (list/arrays of 2D vector components.) –

  • v (list/arrays of 2D vector components.) –

Returns:

q

Return type:

matplotlib’s quiver handle for quiverkey.

Examples

>>> from pandas import date_range
>>> time = date_range(start="1990-11-01 00:00", end="1991-2-1 00:00")
>>> u = np.sin(0.1 * time.to_julian_date().values) ** 2 - 0.5
>>> v = np.cos(0.1 * time.to_julian_date().values)
>>> fig, (ax0, ax1, ax2) = plt.subplots(nrows=3, figsize=(10, 6), sharex=True)
>>> q = stick_plot(time, u, v, ax=ax0)
>>> qk = ax0.quiverkey(
...     q, 0.2, 0.65, 1, "1 m s$^{-1}$", labelpos="N", coordinates="axes"
... )
>>> l = ax1.plot(time.to_pydatetime(), np.sqrt(u**2 + v**2), label="speed")
>>> l0 = ax2.plot(time.to_pydatetime(), u, label="u")
>>> l1 = ax2.plot(time.to_pydatetime(), v, label="v")

Based on Stephane Raynaud’s example from: https://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg18051.html