Exemple #1
0
    def graph_function(
        self,
        func,
        color=BLUE,
        animate=False,
        is_main_graph=True,
    ):
        def parameterized_function(alpha):
            x = interpolate(self.x_min, self.x_max, alpha)
            return self.coords_to_point(x, func(x))

        graph = ParametricFunction(
            parameterized_function,
            color=color,
            num_anchor_points=self.num_graph_anchor_points,
        )
        graph.underlying_function = func

        if is_main_graph:
            self.graph = graph
            self.func = func
        if animate:
            self.play(ShowCreation(graph))
        self.add(graph)
        return graph
Exemple #2
0
    def get_graph(
        self, func, 
        color = None,
        x_min = None,
        x_max = None,
        ):
        if color is None:
            color = self.default_graph_colors_cycle.next()
        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
Exemple #3
0
    def get_graph(
        self, func, 
        color = None,
        x_min = None,
        x_max = None,
        ):
        if color is None:
            color = self.default_graph_colors_cycle.next()
        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
Exemple #4
0
 def get_graph(self, function, num_graph_points=None, **kwargs):
     kwargs["fill_opacity"] = kwargs.get("fill_opacity", 0)
     kwargs["num_anchor_points"] = \
         num_graph_points or self.default_num_graph_points
     graph = ParametricFunction(
         lambda t: self.coords_to_point(t, function(t)),
         t_min=self.x_min,
         t_max=self.x_max,
         **kwargs)
     graph.underlying_function = function
     return graph