Skip to content

Commit 9a7f952

Browse files
committed
Add plot to docstring
1 parent 18084e5 commit 9a7f952

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

doc/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"sphinx.ext.intersphinx",
3737
"sphinx.ext.viewcode",
3838
"sphinx_gallery.gen_gallery",
39+
"matplotlib.sphinxext.plot_directive",
40+
3941
]
4042

4143
autoclass_content = 'both'

src/py_eddy_tracker/generic.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
isnan,
3939
bool_,
4040
concatenate,
41+
radians,
4142
)
4243
from numba import njit, prange, types as numba_types
4344
from .poly import winding_number_grid_in_poly
@@ -497,3 +498,18 @@ def get_pixel_in_regular(vertices, x_c, y_c, x_start, x_stop, y_start, y_stop):
497498
y_start,
498499
vertices,
499500
)
501+
502+
503+
def build_circle(x0, y0, r):
504+
"""
505+
Method to built circle from center coordinates
506+
507+
:param float x0: center coordinate
508+
:param float y0: center coordinate
509+
:param float r: radius i meter
510+
:return: x,y
511+
:rtype: (array,array)
512+
"""
513+
angle = radians(linspace(0, 360, 50))
514+
x_norm, y_norm = cos(angle), sin(angle)
515+
return x_norm * r + x0, y_norm * r + y0

src/py_eddy_tracker/poly.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,24 @@ def fit_circle_(x, y):
382382
:param array y: y of polygon
383383
:return: x0, y0, radius, shape_error
384384
:rtype: (float,float,float,float)
385+
386+
.. plot::
387+
388+
import matplotlib.pyplot as plt
389+
import numpy as np
390+
from py_eddy_tracker.poly import fit_circle_
391+
from py_eddy_tracker.generic import build_circle
392+
V = np.array(((2, 2, 3, 3, 2), (-10, -9, -9, -10, -10)), dtype='f4')
393+
x0, y0, radius, err = fit_circle_(V[0], V[1])
394+
ax = plt.subplot(111)
395+
ax.set_aspect('equal')
396+
ax.grid(True)
397+
ax.plot(*build_circle(x0,y0, radius), 'r')
398+
ax.plot(x0, y0, 'r+')
399+
ax.plot(*V, 'b.')
400+
plt.show()
385401
"""
386-
datas = ones((x.shape[0] - 1, 3))
402+
datas = ones((x.shape[0] - 1, 3), dtype=x.dtype)
387403
# we skip first position which are the same than the last
388404
datas[:, 0] = x[1:]
389405
datas[:, 1] = y[1:]

0 commit comments

Comments
 (0)