pyyeti.ytools.fit_circle_2d

pyyeti.ytools.fit_circle_2d(x, y, makeplot='no')[source]

Find radius and center point of x-y data points

Parameters:
  • x, y (1d array_like) – Vectors x, y data points (in cartesian coordinates) that are on a circle: [x, y]

  • makeplot (string or axes object; optional) – Specifies if and how to plot data showing the fit.

    makeplot

    Description

    ‘no’

    do not plot

    ‘clear’

    plot after clearing figure

    ‘add’

    plot without clearing figure

    ‘new’

    plot in new figure

    axes object

    plot in given axes (like ‘add’)

Returns:

p (1d ndarray) – Vector: [xc, yc, R] where (xc, yc) defines the center of the circle and R is the radius.

Notes

Uses scipy.optimize.leastsq() to find optimum circle parameters.

Examples

For a test, provide precise x, y coordinates, but only for a 1/4 circle:

>>> import numpy as np
>>> from pyyeti.ytools import fit_circle_2d
>>> xc, yc, R = 1., 15., 35.
>>> th = np.linspace(0., np.pi/2, 10)
>>> x = xc + R*np.cos(th)
>>> y = yc + R*np.sin(th)
>>> fit_circle_2d(x, y, makeplot='new')
array([  1.,  15.,  35.])
../../_images/pyyeti-ytools-fit_circle_2d-1.png