A community-maintained Python framework for creating mathematical animations.
Implemented :meth:`.CoordinateSystem.plot_antiderivative_graph` (#2267)
icedcoffeeee81940786579b
diff --git a/manim/mobject/coordinate_systems.py b/manim/mobject/coordinate_systems.pyindex 03a6ec11f..18b4c0995 100644--- a/manim/mobject/coordinate_systems.py+++ b/manim/mobject/coordinate_systems.py@@ -1447,6 +1447,60 @@ class CoordinateSystem:) -> ParametricFunction:return self.plot_derivative_graph(graph, color, **kwargs)+ def plot_antiderivative_graph(+ self,+ graph: ParametricFunction,+ y_intercept: float = 0,+ samples: int = 50,+ **kwargs,+ ):+ """Plots an antiderivative graph.++ Examples+ --------+ .. manim:: AntiderivativeExample+ :save_last_frame:++ class AntiderivativeExample(Scene):+ def construct(self):+ ax = Axes()+ graph1 = ax.plot(+ lambda x: (x ** 2 - 2) / 3,+ color=RED,+ )+ graph2 = ax.plot_antiderivative_graph(graph1, color=BLUE)+ self.add(ax, graph1, graph2)++ .. note::+ This graph is plotted from the values of area under the reference graph.+ The result might not be ideal if the reference graph contains uncalculatable+ areas from x=0.++ Parameters+ ----------+ graph+ The graph for which the antiderivative will be found.+ y_intercept+ The y-value at which the graph intercepts the y-axis.+ samples+ The number of points to take the area under the graph.+ **kwargs+ Any valid keyword argument of :class:`~.ParametricFunction`++ Returns+ -------+ :class:`~.ParametricFunction`+ The curve of the antiderivative.+ """++ def antideriv(x):+ x_vals = np.linspace(0, x, samples)+ f_vec = np.vectorize(graph.underlying_function)+ y_vals = f_vec(x_vals)+ return np.trapz(y_vals, x_vals) + y_intercept++ return self.plot(antideriv, **kwargs)+def get_secant_slope_group(self,x: float,diff --git a/tests/test_graphical_units/control_data/plot/plot_derivative_graph.npz b/tests/test_graphical_units/control_data/plot/plot_derivative_graph.npzindex da26cc739..7101141de 100644Binary files a/tests/test_graphical_units/control_data/plot/plot_derivative_graph.npz and b/tests/test_graphical_units/control_data/plot/plot_derivative_graph.npz differdiff --git a/tests/test_graphical_units/test_axes.py b/tests/test_graphical_units/test_axes.pyindex 036710a55..fcec71bcd 100644--- a/tests/test_graphical_units/test_axes.py+++ b/tests/test_graphical_units/test_axes.py@@ -71,7 +71,8 @@ def test_plot_derivative_graph(scene):curve_1 = ax.plot(lambda x: x ** 2, color=PURPLE_B)curve_2 = ax.plot_derivative_graph(curve_1)- curves = VGroup(curve_1, curve_2)+ curve_3 = ax.plot_antiderivative_graph(curve_1)+ curves = VGroup(curve_1, curve_2, curve_3)scene.add(ax, curves)