GraphScene
(x_min= 1, x_max=10, x_axis_width=9, x_leftmost_tick=None, x_labeled_nums=None, x_axis_label='$x$', y_min= 1, y_max=10, y_axis_height=6, y_bottom_tick=None, y_labeled_nums=None, y_axis_label='$y$', axes_color='#888888', graph_origin=array([ 4.0,  2.5, 0.0]), exclude_zero_label=True, default_graph_colors=['#58C4DD', '#83C167', '#FFFF00'], default_derivative_color='#83C167', default_input_color='#FFFF00', default_riemann_start_color='#58C4DD', default_riemann_end_color='#83C167', area_opacity=0.8, num_rects=50, include_tip=False, x_axis_visibility=True, y_axis_visibility=True, x_label_position=array([1.0, 1.0, 0.0]), y_label_position=array([1.0, 1.0, 0.0]), x_axis_config={}, y_axis_config={}, **kwargs)[source]¶Bases: manim.scene.scene.Scene
Methods
Create a triangle marker with a vertical line from the xaxis to 

Returns the angle to the x axis of the tangent to the plotted curve at a particular xvalue. 

This method animates the change of the secant slope group from the old secant slope group, into a new secant slope group. 

The graph is smaller than the scene. 

This method requires a lot of prerequisites: self.area must be defined from self.get_area() self.left_v_line and self.right_v_line must be defined from self.get_v_line self.left_T_label_group and self.right_T_label_group must be defined from self.add_T_label 

Returns a VGroup of Riemann rectangles sufficiently small enough to visually approximate the area under the graph passed. 

Returns the curve of the derivative of the passed graph. 

This method gets a curve to plot on the graph. 

This method returns a properly positioned label for the passed graph, styled with the passed parameters. 

This method returns the VGroup() of the Riemann Rectangles for a particular curve. 

This method returns a list of multiple VGroups of Riemann Rectangles. 

This method returns a VGroup of (two lines representing dx and df, the labels for dx and df, and the Secant to the Graph/curve at a particular x value. 

This method returns a Vertical line from the xaxis to the corresponding point on the graph/curve. 

Obtains multiple lines from the x axis to the Graph/curve. 

This method returns a coordinate on the curve given an x_value and a the graphcurve for which the corresponding y value should be found. 

The scene is smaller than the graph. 

This method is used internally by Manim to set up the scene for proper use. 

This method sets up the axes of the graph. 

Returns the slope of the tangent to the plotted curve at a particular xvalue. 

This method is used to transform between two VGroups of Riemann Rectangles, if they were obtained by get_riemann_rectangles or get_riemann_rectangles_list. 
Attributes

add_T_label
(x_val, side=array([1.0, 0.0, 0.0]), label=None, color='#FFFFFF', animated=False, **kwargs)[source]¶Create a triangle marker with a vertical line from the xaxis
to self.v_graph
at the given x coordinate x_val
.
This method adds to the Scene:
a Vertical line from the xaxis to the corresponding point on the graph/curve.
a small vertical Triangle whose top point lies on the base of the vertical line
a MathTex to be a label for the Line and Triangle, at the bottom of the Triangle.
The scene needs to have the graph have the identifier/variable
name self.v_graph
.
x_val (float, int) – The x value at which the secant enters, and intersects the graph for the first time.
side (np.array(), optional) –
label (str, optional) – The label to give the vertical line and triangle
color (str, optional) – The hex color of the label.
animated (bool, optional) – Whether or not to animate the addition of the T_label
**kwargs – Any valid keyword argument of a self.play call.
angle_of_tangent
(x, graph, dx=0.01)[source]¶Returns the angle to the x axis of the tangent to the plotted curve at a particular xvalue.
x (int, float) – The x value at which the tangent must touch the curve.
graph (ParametricFunction) – The ParametricFunction for which to calculate the tangent.
dx (int, float, optional) – The small change in x with which a small change in y will be compared in order to obtain the tangent.
The angle of the tangent with the x axis.
float
animate_secant_slope_group_change
(secant_slope_group, target_dx=None, target_x=None, run_time=3, added_anims=None, **anim_kwargs)[source]¶This method animates the change of the secant slope group from the old secant slope group, into a new secant slope group.
secant_slope_group (VGroup) – The old secant_slope_group
target_dx (int, float, optional) – The new dx value.
target_x (int, float, optional) – The new x value at which the secant should be.
run_time (int, float, optional) – The run time for this change when animated.
added_anims (list, optional) – Any exta animations that should be played alongside.
**anim_kwargs – Any valid kwargs of a self.play call.
NOTE (At least one of target_dx and target_x should be not None.) –
coords_to_point
(x, y)[source]¶The graph is smaller than the scene. Because of this, coordinates in the scene don’t map to coordinates on the graph. This method returns a scaled coordinate for the graph, given cartesian coordinates that correspond to the scene..
x (int, float) – The x value
y (int, float) – The y value
The array of the coordinates.
np.ndarray
Examples
class SequencePlot(GraphScene):
def __init__(self, **kwargs):
GraphScene.__init__(
self,
y_axis_label=r"Concentration [\%]",
x_axis_label="Time [s]",
**kwargs
)
def construct(self):
data = [1, 2, 2, 4, 4, 1, 3]
self.setup_axes()
for time, dat in enumerate(data):
dot = Dot().move_to(self.coords_to_point(time, dat))
self.add(dot)
get_animation_integral_bounds_change
(graph, new_t_min, new_t_max, fade_close_to_origin=True, run_time=1.0)[source]¶This method requires a lot of prerequisites: self.area must be defined from self.get_area() self.left_v_line and self.right_v_line must be defined from self.get_v_line self.left_T_label_group and self.right_T_label_group must be defined from self.add_T_label
This method will return a VGroup of new mobjects for each of those, when provided the graph/curve, the new t_min and t_max, the run_time and a bool stating whether or not to fade when close to the origin.
graph (ParametricFunction) – The graph for which this must be done.
new_t_min (int, float) – The new lower bound.
new_t_max (int, float) – The new upper bound.
fade_close_to_origin (bool, optional) – Whether or not to fade when close to the origin.
run_time (int, float, optional) – The run_time of the animation of this change.
get_area
(graph, t_min, t_max, bounded=None, dx_scaling=1, area_color='#FFFFFF')[source]¶Returns a VGroup of Riemann rectangles sufficiently small enough to visually approximate the area under the graph passed.
graph (ParametricFunction) – The graph/curve for which the area needs to be gotten.
t_min (int, float) – The lower bound of x from which to approximate the area.
t_max (int, float) – The upper bound of x until which the area must be approximated.
The VGroup containing the Riemann Rectangles.
get_derivative_graph
(graph, dx=0.01, **kwargs)[source]¶Returns the curve of the derivative of the passed graph.
graph (ParametricFunction) – The graph for which the derivative must be found.
dx (float, int, optional) – The small change in x with which a small change in y will be compared in order to obtain the derivative.
**kwargs – Any valid keyword argument of ParametricFunction
The curve of the derivative.
get_graph
(func, color=None, x_min=None, x_max=None, **kwargs)[source]¶This method gets a curve to plot on the graph.
func (function) – The function to plot. It’s return value should be the ycoordinate for a given xcoordinate
color (str, optional) – The string of the RGB color of the curve. in Hexadecimal representation.
x_min (int, float, optional) – The lower x_value from which to plot the curve.
x_max (int, float, optional) – The higher x_value until which to plot the curve.
**kwargs – Any valid keyword arguments of ParametricFunction.
The Parametric Curve for the function passed.
get_graph_label
(graph, label='f(x)', x_val=None, direction=array([1.0, 0.0, 0.0]), buff=0.25, color=None)[source]¶This method returns a properly positioned label for the passed graph, styled with the passed parameters.
graph (ParametricFunction) – The curve of the function plotted.
label (str, optional) – The label for the function’s curve.
x_val (int, float, optional) – The x_value with which the label should be aligned.
direction (np.ndarray, list, tuple) – The cartesian position, relative to the curve that the label will be at. e.g LEFT, RIGHT
buff (float, int, option) – The buffer space between the curve and the label
color (str, optional) – The color of the label.
The LaTeX of the passed ‘label’ parameter
get_riemann_rectangles
(graph, x_min=None, x_max=None, dx=0.1, input_sample_type='left', bounded_graph=None, stroke_width=1, stroke_color='#000000', fill_opacity=1, start_color=None, end_color=None, show_signed_area=True, width_scale_factor=1.001)[source]¶This method returns the VGroup() of the Riemann Rectangles for a particular curve.
graph (ParametricFunction) – The graph whose area needs to be approximated by the Riemann Rectangles.
x_min (int, float, optional) – The lower bound from which to start adding rectangles
x_max (int, float, optional) – The upper bound where the rectangles stop.
dx (int, float, optional) – The smallest change in xvalues that is considered significant.
input_sample_type ({"left", "right", "center"}) – Can be any of “left”, “right” or “center
stroke_width (int, float, optional) – The stroke_width of the border of the rectangles.
stroke_color (str, optional) – The string of hex colour of the rectangle’s border.
fill_opacity (int, float) – The opacity of the rectangles. Takes values from 0 to 1.
start_color (str, optional) – The hex starting colour for the rectangles, this will, if end_color is a different colour, make a nice gradient.
end_color (str, optional) – The hex ending colour for the rectangles, this will, if start_color is a different colour, make a nice gradient.
show_signed_area (bool, optional) – Whether or not to indicate ve area if curve dips below xaxis.
width_scale_factor (int, float, optional) – How much the width of the rectangles are scaled by when transforming.
A VGroup containing the Riemann Rectangles.
get_riemann_rectangles_list
(graph, n_iterations, max_dx=0.5, power_base=2, stroke_width=1, **kwargs)[source]¶This method returns a list of multiple VGroups of Riemann Rectangles. The initial VGroups are relatively inaccurate, but the closer you get to the end the more accurate the Riemann rectangles become
graph (ParametricFunction) – The graph whose area needs to be approximated by the Riemann Rectangles.
n_iterations (int,) – The number of VGroups of successive accuracy that are needed.
max_dx (int, float, optional) – The maximum change in x between two VGroups of Riemann Rectangles
power_base (int, float, optional) – Defaults to 2
stroke_width (int, float, optional) – The stroke_width of the border of the rectangles.
**kwargs – Any valid keyword arguments of get_riemann_rectangles.
The list of Riemann Rectangles of increasing accuracy.
list
get_secant_slope_group
(x, graph, dx=None, dx_line_color=None, df_line_color=None, dx_label=None, df_label=None, include_secant_line=True, secant_line_color=None, secant_line_length=10)[source]¶This method returns a VGroup of (two lines representing dx and df, the labels for dx and df, and the Secant to the Graph/curve at a particular x value.
x (int, float) – The x value at which the secant enters, and intersects the graph for the first time.
graph (ParametricFunction) – The curve/graph for which the secant must be found.
dx (int, float, optional) – The change in x after which the secant exits.
dx_line_color (str, optional) – The line color for the line that indicates the change in x.
df_line_color (str, optional) – The line color for the line that indicates the change in y.
dx_label (str, optional) – The label to be provided for the change in x.
df_label (str, optional) – The label to be provided for the change in y.
include_secant_line (bool, optional) – Whether or not to include the secant line in the graph, or just have the df and dx lines and labels.
secant_line_color (str, optional) – The color of the secant line.
secant_line_length (int, float, optional) – How long the secant line should be.
A group containing the elements dx_line
, df_line
, and
if applicable also dx_label
, df_label
, secant_line
.
get_vertical_line_to_graph
(x, graph, line_class=<class 'manim.mobject.geometry.Line'>, **line_kwargs)[source]¶This method returns a Vertical line from the xaxis to the corresponding point on the graph/curve.
x (int, float) – The xvalue at which the line should be placed/calculated.
graph (ParametricFunction) – The graph on which the line should extend to.
line_class (Line and similar) – The type of line that should be used. Defaults to Line.
**line_kwargs – Any valid keyword arguments of the object passed in “line_class” If line_class is Line, any valid keyword arguments of Line are allowed.
Defaults to Line
An object of type passed in “line_class”
get_vertical_lines_to_graph
(graph, x_min=None, x_max=None, num_lines=20, **kwargs)[source]¶Obtains multiple lines from the x axis to the Graph/curve.
graph (ParametricFunction) – The graph on which the line should extend to.
x_min (int, float, optional) – The lower bound from which lines can appear.
x_max (int, float, optional) – The upper bound until which the lines can appear.
num_lines (int, optional) – The number of lines (evenly spaced) that are needed.
The VGroup of the evenly spaced lines.
input_to_graph_point
(x, graph)[source]¶This method returns a coordinate on the curve given an x_value and a the graphcurve for which the corresponding y value should be found.
x (int, float) – The x value for which to find the y value.
graph (ParametricFunction) – The ParametricFunction object on which the x and y value lie.
The array of the coordinates on the graph.
numpy.nparray
point_to_coords
(point)[source]¶The scene is smaller than the graph.
Because of this, coordinates in the graph don’t map to coordinates on the scene.
This method returns a scaled coordinate for the scene, given coordinates that correspond to the graph.
point (np.ndarray) – The point on the graph.
The coordinates on the scene.
tuple
setup_axes
(animate=False)[source]¶This method sets up the axes of the graph.
animate (bool, optional) – Whether or not to animate the setting up of the Axes.
slope_of_tangent
(*args, **kwargs)[source]¶Returns the slope of the tangent to the plotted curve at a particular xvalue.
x (int, float) – The x value at which the tangent must touch the curve.
graph (ParametricFunction) – The ParametricFunction for which to calculate the tangent.
dx (int, float, optional) – The small change in x with which a small change in y will be compared in order to obtain the tangent.
The slope of the tangent with the x axis.
float