def get_graph( self, func, color=None, x_min=None, x_max=None, **kwargs ): if color is None: color = next(self.default_graph_colors_cycle) if x_min is None: x_min = self.x_min if x_max is None: x_max = self.x_max def parameterized_function(alpha): x = interpolate(x_min, x_max, alpha) y = func(x) if not np.isfinite(y): y = self.y_max return self.coords_to_point(x, y) graph = ParametricFunction( parameterized_function, color=color, **kwargs ) graph.underlying_function = func return graph
def add_curve(self, func, color=None, x_min=None, x_max=None, parameters=None, **kwargs): if color is None: color = next(self.default_graph_colors_cycle) if x_min is None: x_min = self.x_min if x_max is None: x_max = self.x_max def parameterized_function(alpha, **parameters): x = interpolate(x_min, x_max, alpha) y = func(x, **parameters) if not np.isfinite(y): y = self.y_max return self.coords_to_point(x, y) curve = ParametricFunction(parameterized_function, parameters=parameters, color=color, **kwargs) curve.underlying_function = func if hasattr(self, "curves") is False: self.curves = VGroup() self.curves.add(curve) self.add(self.curves) return curve
def make_path(func, x_min=0, x_max=1, y_max=None, y_infinity=10, color="#ffffff", **kwargs): def parametric(alpha=1, override_x=None): if override_x == None: x = interpolate(x_min, x_max, alpha) else: x = override_x y = func(x) if not np.isfinite(y) or (y_max and y >= y_max): y = y_infinity return (x, y, 0) path = ParametricFunction(parametric, color=color, **kwargs) path.underlying_function = func path.para_func = parametric path.x_min = x_min path.x_max = x_max return path
def get_parametric_curve(self, function, **kwargs): dim = self.dimension graph = ParametricFunction( lambda t: self.coords_to_point( *function(t)[:dim] ), **kwargs ) graph.underlying_function = function return graph
def get_graph(self, function, **kwargs): x_min = kwargs.pop("x_min", self.x_min) x_max = kwargs.pop("x_max", self.x_max) graph = ParametricFunction( lambda t: self.coords_to_point(t, function(t)), t_min=x_min, t_max=x_max, **kwargs) graph.underlying_function = function return graph
def get_graph( self, func, color=None, x_min=None, x_max=None, **kwargs ): """ This method gets a curve to plot on the graph. Parameters ---------- func : function The function to plot. It's return value should be the y-coordinate for a given x-coordinate color : str The string of the RGB color of the curve. in Hexadecimal representation. x_min : (Union[int,float]) The lower x_value from which to plot the curve. x_max : (Union[int,float]) The higher x_value until which to plot the curve. **kwargs: Any valid keyword arguments of ParametricFunction. Return ------ ParametricFunction The Parametric Curve for the function passed. """ if color is None: color = next(self.default_graph_colors_cycle) if x_min is None: x_min = self.x_min if x_max is None: x_max = self.x_max def parameterized_function(alpha): x = interpolate(x_min, x_max, alpha) y = func(x) if not np.isfinite(y): y = self.y_max return self.coords_to_point(x, y) graph = ParametricFunction( parameterized_function, color=color, **kwargs ) graph.underlying_function = func return graph
def get_graph(self, function, num_graph_points=None, x_min=None, x_max=None, **kwargs): kwargs["fill_opacity"] = kwargs.get("fill_opacity", 0) kwargs["num_anchor_points"] = \ num_graph_points or self.default_num_graph_points x_min = x_min or self.x_min x_max = x_max or self.x_max graph = ParametricFunction( lambda t: self.coords_to_point(t, function(t)), t_min=x_min, t_max=x_max, **kwargs) graph.underlying_function = function return graph
def get_graph( self, func, color=None, x_min=None, x_max=None, ): """ Parameters ---------- func : Function This function must be continuous color : Hexadecimal color Color x_min : float TODO x_max : float TODO """ if color is None: color = next(self.default_graph_colors_cycle) if x_min is None: x_min = self.x_min if x_max is None: x_max = self.x_max def parameterized_function(alpha): x = interpolate(x_min, x_max, alpha) y = func(x) if not np.isfinite(y): y = self.y_max return self.coords_to_point(x, y) graph = ParametricFunction( parameterized_function, color=color, num_anchor_points=self.num_graph_anchor_points, ) graph.underlying_function = func return graph