0

So manim is installed correctly i can transform i can see latex formulas and all but i was trying to plot a graph

from manimlib.imports import *

class PlotFunctions(GraphScene):
    CONFIG = {
    "x_min" : -10,
    "x_max" : 10,
    "x_tick_frequency": 1,
    "y_min" : -15,
    "y_max" : 15,
    "y_tick_frequency": 1,
    "graph_origin" : ORIGIN ,
    "function_color" : RED ,
    "axes_color" : GREEN,
    "x_labeled_nums" :range(-10,10,5),
    "y_labeled_nums":range(-15,15,5),

    }
    def construct(self):
        self.setup_axes(animate=True)
        func_graph=self.get_graph(self.func_to_graph,self.function_color)
        func_graph2=self.get_graph(self.func_to_graph2)
        #vert_line = self.get_vertical_line_to_graph(TAU,func_graph,color=YELLOW)
        #graph_lab = self.get_graph_label(func_graph, label = "\\cos(x)")
        #graph_lab2=self.get_graph_label(func_graph2,label = "\\sin(x)", x_val=-10, direction=UP/2)
        #two_pi = TexMobject("x = 2 \\pi")
        #label_coord = self.input_to_graph_point(TAU,func_graph)
        #two_pi.next_to(label_coord,RIGHT+UP)

        self.play(ShowCreation(func_graph),ShowCreation(func_graph2))
        #self.play(ShowCreation(vert_line), ShowCreation(graph_lab), ShowCreation(graph_lab2),ShowCreation(two_pi))

    def func_to_graph(self,x):
        return x*x

    def func_to_graph2(self,x):
        a=x-1
        b=x-2
        c=x-3
        d=x-4
        e=a*b
        f=c*d
        g=e/f
        return g


in the last part where I used a b c d, I was just trying to define (x-1)(x-2)/(x-3)(x-4) and i tried normally but i was stil getting the wrong graph this is the wrong graph

and this is the correct graph

any and all help is appreciated , Thank You very much i am an amateur who studied c++ functions and all but i dont really know why the x is where it is and not elsewhere , i dot really get anything so try to keep it in laymans terms if possible

1 Answers1

0

First, you must identify the domains that are continuous, that is, (a, b), [c, d), etc. Once you have them, you must create a graph for each of the domains, that is:

    grap1 = self.get_graph(lambda x:f(x), x_min = 1.001*a, x_max = 0.999*b)
    grap2 = self.get_graph(lambda x:f(x), x_min = c, x_max = 0.999*d)
    # and so on

Then, you can group them all in a graph

    graph = VMobject(graph1,graph2)
    self.play(LaggedStartMap(ShowCreation,graph))

Here is an example. Here is my video tutorial about Graphs.

TheoremOfBeethoven
  • 1,864
  • 6
  • 15