본문 바로가기

Programming/Manim code

[34]GraphScene

반응형
class GraphSceneTest(GraphScene):
    CONFIG = {
        "x_axis_label": "",
        "y_axis_label": "",
        "x_min": 0,
        "x_max": 15,
        "x_axis_width": 12,

        "y_min": 0,
        "y_max": 0.5,
        "y_axis_height": 6,
        "y_tick_frequency": 0.125,

        "graph_origin": 2.5 * DOWN + 5.5 * LEFT,
    }

    def construct(self):
        self.setup_axes()
        self.y_axis.add_numbers(
            0.25, 0.5, 0.75, 1,
            number_config={
                "num_decimal_places": 2,
            },
            direction=LEFT,
        )
        self.x_axis.add_numbers(*range(1, 15))

        graph1 = self.get_prior_graph()
        self.add(graph1)
        self.wait()

    def get_prior_graph(self):
        def prior(x):
            return ((x ** 3 / 6) * np.exp(-x))

        return self.get_graph(prior)

 

 

 


get_riemann_rectangles

class GraphSceneTest(GraphScene):
    CONFIG = {
        "x_axis_label": "",
        "y_axis_label": "",
        "x_min": 0,
        "x_max": 15,

        "x_axis_width": 12,
        "y_min": 0,
        "y_max": 0.5,
        "y_axis_height": 6,
        "y_tick_frequency": 0.125,

        "graph_origin": 2.5 * DOWN + 5.5 * LEFT,
    }

    def construct(self):
        self.setup_axes()
        self.y_axis.add_numbers(
            0.25, 0.5, 0.75, 1,
            number_config={
                "num_decimal_places": 2,
            },
            direction=LEFT,
        )
        self.x_axis.add_numbers(*range(1, 15))

        graph = self.get_prior_graph()
        self.play(ShowCreation(graph), run_time=3)
        self.wait()

        #riemann rectangle
        rect = self.get_riemann_rectangles(graph, dx=0.2)
        rect.set_color(YELLOW_D)
        rect.set_stroke(WHITE, 1)

        self.play(ShowCreation(rect), run_time=5)
        self.wait()

    def get_prior_graph(self):
        def prior(x):
            return ((x ** 3 / 6) * np.exp(-x))

        return self.get_graph(prior)

 

 

 

반응형

'Programming > Manim code' 카테고리의 다른 글

[38]Animation: Creation  (0) 2020.05.12
[37]Animation's rate_func  (0) 2020.05.12
[33]NumberPlane  (0) 2020.05.12
[032]Axes  (0) 2020.05.11
[031]NumberLine  (0) 2020.05.11