graphinglib.FitFromPolynomial#
- class graphinglib.FitFromPolynomial(curve_to_be_fit: Curve | Scatter, degree: int, label: str | None = None, color: str | Inherit = Inherit, line_width: int | Inherit = Inherit, line_style: int | Inherit = Inherit, alpha: float | Inherit = Inherit)[source]#
Creates a curve fit (continuous
Curve) from an existing curve object using a polynomial fit.Fits a polynomial of the form \(f(x) = a_0 + a_1 x + a_2 x^2 + ... + a_n x^n\) to the given curve. All standard Curve attributes and methods are available.
- Parameters:
- curve_to_be_fit
CurveorScatter The object to be fit.
- degreeint
Degree of the polynomial fit.
- labelstr, optional
Label to be displayed in the legend.
- colorstr
Color of the
Curve. Default depends on thefigure_styleconfiguration.- line_widthint
Line width of the
Curve. Typical range is0.5to4. Default depends on thefigure_styleconfiguration.- line_stylestr
Line style of the
Curve. Values include"-","--","-.",":","solid","dashed","dashdot", and"dotted". Default depends on thefigure_styleconfiguration.- alphafloat
Opacity of the
Curve. Range is0(transparent) to1(opaque). Default depends on thefigure_styleconfiguration.
- curve_to_be_fit
- Attributes:
- coeffsnp.ndarray
Coefficients of the polynomial fit. The first element is the coefficient of the lowest order term (constant term).
- cov_matrixnp.ndarray
Covariance matrix of the polynomial fit (using the same order as the coeffs attribute).
- standard_deviationnp.ndarray
Standard deviation of the coefficients of the polynomial fit (same order as coeffs).
- functionCallable
Polynomial function with the parameters of the fit.
Notes
Color parameters accept Matplotlib color formats: named colors (
"blue"), short color strings ("b"), hex strings ("#0000ff"), grayscale strings ("0.5"), and RGB/RGBA tuples with values between0and1((0, 0, 1)or(0, 0, 1, 0.5)).Methods
__init__(curve_to_be_fit, degree[, label, ...])Creates a curve fit (continuous
Curve) from an existing curve object using a polynomial fit.add_error_curves([y_error, ...])Adds error curves to the
Curve.add_errorbars([x_error, y_error, cap_width, ...])Adds errorbars to the
Curve.copy()Returns a deep copy of the
Curve.copy_with(**kwargs)Returns a deep copy of the Plottable with specified attributes overridden.
create_derivative_curve([label, color, ...])Creates a new curve which is the derivative of the original curve.
create_integral_curve([initial_value, ...])Creates a new curve which is the integral of the original curve.
create_intersection_points(other[, labels, ...])Creates the intersection Points between two curves.
create_normal_curve(x[, label, color, ...])Creates a new curve which is the normal to the original curve at a given x value.
create_point_at_x(x[, label, face_color, ...])Gets the point on the curve at a given x value.
create_points_at_y(y[, interpolation_kind, ...])Creates the Points on the curve at a given y value.
create_slice_x(x1, x2[, label, color, ...])Creates a slice of the curve between two x values.
create_slice_y(y1, y2[, label, color, ...])Creates a slice of the curve between two y values.
create_tangent_curve(x[, label, color, ...])Creates a new curve which is the tangent to the original curve at a given x value.
from_function(func, x_min, x_max[, label, ...])Creates a
Curvefrom a function and a range of x values.Calculates the \(R^2\) value of the fit curve.
get_arc_length_between(x1, x2)Calculates the arc length of the curve between two x values.
get_area_between(x1, x2[, fill_between, ...])Calculates the area between the curve and the x axis between two x values.
Gets the coordinates of the curve at a given x value.
get_coordinates_at_y(y[, interpolation_method])Gets the coordinates of the curve at a given y value.
get_intersection_coordinates(other)Calculates the coordinates of the intersection points between two curves.
Calculates the residuals of the fit curve.
get_slope_at(x)Calculates the slope of the curve at a given x value.
show_residual_curves([sigma_multiplier, ...])Displays two curves
"sigma_multiplier"standard deviations above and below the fit curve.to_desmos([decimal_precision, to_clipboard])Gives the data points in a Desmos-readable format.