Python Manim Code with Video Output


from manim import *
class MathTableExample(Scene):
def construct(self):
                text1 = Tex("Arithmatic Mean",font_size=50)
                sr1=SurroundingRectangle(text1[0],color=RED, buff=MED_LARGE_BUFF)
                mobj1 = VGroup(VGroup(sr1, text1)).arrange(UP)
                mobj1.move_to(2*UP)
                self.add(mobj1)
                self.play(Create( mobj1))
                self.wait(15)
                #####################################
                text2=MathTex(r"Observations-->x_1, x_2, x_3,.....,x_n \\ \text{Number of Observations}--> n",font_size=40)
                sr2=SurroundingRectangle(text2[0],color=YELLOW, buff=MED_LARGE_BUFF)
                mobj2 = VGroup(VGroup(sr2, text2))
                self.add(mobj2)
                self.play(Create( mobj2))
                self.wait(10)
                self.play(FadeOut(mobj2))
               #####################################
                text3=MathTex(r"mean=\frac{x_1+x_2+x_3+........+x_n}{n}",font_size=40)
                sr3=SurroundingRectangle(text3[0],color=YELLOW, buff=MED_LARGE_BUFF)
                mobj3= VGroup(VGroup(sr3, text3))
                self.add(mobj3)
                self.play(Create( mobj3))
                self.wait(10)
                self.play(FadeOut(mobj3))
               #####################################
               text4=MathTex(r"mean=\frac{\sum x_i}{n}",font_size=40)
               sr4=SurroundingRectangle(text4[0],color=YELLOW, buff=MED_LARGE_BUFF)
               mobj4 = VGroup(VGroup(sr4, text4))
               self.add(mobj4)
               self.play(Create( mobj4))
               self.wait(10)
               self.play(FadeOut(mobj4))
               self.play(FadeOut(mobj4))
              ##############################
               #############################
               text5=MathTex(r"Observations-->93,96,85,88,70 \\ \text{Number of Observations}--> 5",font_size=40)
               sr5=SurroundingRectangle(text5[0],color=YELLOW, buff=MED_LARGE_BUFF)
               mobj5 = VGroup(VGroup(sr5, text5))
               self.add(mobj5)
               self.play(Create( mobj5))
               self.wait(10)
               self.play(FadeOut(mobj5))
               #####################################
               text6=MathTex(r"mean=\frac{93+96+85+88+70}{5}",font_size=40)
               sr6=SurroundingRectangle(text6[0],color=YELLOW, buff=MED_LARGE_BUFF)
               mobj6= VGroup(VGroup(sr6, text6))
               self.add(mobj6)
               self.play(Create( mobj6))
               self.wait(10)
               self.play(FadeOut(mobj6))
              #####################################
               text7=MathTex(r"mean=\frac{432}{5}",font_size=40)
               sr7=SurroundingRectangle(text7[0],color=YELLOW, buff=MED_LARGE_BUFF)
               mobj7 = VGroup(VGroup(sr7, text7))
               self.add(mobj7)
               self.play(Create( mobj7))
               self.wait(10)
               self.play(FadeOut(mobj7))
              #####################################
              text7=MathTex(r"mean=86.40",font_size=40)
              sr7=SurroundingRectangle(text7[0],color=YELLOW, buff=MED_LARGE_BUFF)
              mobj7 = VGroup(VGroup(sr7, text7))
              self.add(mobj7)
              self.play(Create( mobj7))
              self.wait(10)
              self.play(FadeOut(mobj7))
              self.play(FadeOut(mobj1))
             ##############################
             ###############################
              text4= Tex("Arithmatic Mean of Frequency Distribution",font_size=50)
              sr4=SurroundingRectangle(text4[0],color=RED, buff=MED_LARGE_BUFF)
              mobj4= VGroup(VGroup(sr4, text4)).arrange(UP)
              mobj4.move_to(2*UP)
              self.add(mobj4)
              self.play(Create(mobj4))
              self.wait(15)
              o=["x_i",93,96,85,88,70,"" ]
              f=["f_i",1,2,3,1,3,"N=10"]
              l=[o,f]
              tb1=MathTable(l,include_outer_lines=True).scale(0.70)
              # tb1.move_to(UP)
               for i in range(1,8):
                     self.add(tb1)
                     srt=SurroundingRectangle(tb1.get_columns()[i-1])
                     srt= VGroup(VGroup(srt))
                     tb1.add(srt)
                     self.wait(3)
                     self.play(FadeOut(tb1))
              #of=["f_i * x_i",93,192,255,88,210,"Total=838"]
               fmo=["x_i * f_i","93 * 1","96 * 2","85 * 3","88 * 1","70 * 2"]
               l=[fmo]
              tb2=MathTable(l, include_outer_lines=True).scale(0.60)
              tb1.move_to(2*DOWN)
              for i in range(1,2):
                          for j in range(1, 7):
                                  self.add(tb2)
                                  srt2=SurroundingRectangle(tb2.get_highlighted_cell((i,j), color=GREEN))
                                  srt2= VGroup(VGroup(srt2))
                                  tb2.add(srt2)
                                  self.wait(3)
                                  self.play(FadeOut(tb2))
             text5=MathTex(r"mean=\frac{\sum f_i * x_i}{N}",font_size=50)
             sr5=SurroundingRectangle(text5[0],color=YELLOW, buff=MED_LARGE_BUFF)
             mobj5= VGroup(VGroup(sr5, text5)).arrange(UP)
             self.add(mobj5)
             self.play(Create( mobj5))
             self.wait(10)
             self.play(FadeOut(mobj5))
             text6=MathTex(r"mean=\frac{93 * 1 + 96 * 2 + 85 * 3 + 88 * 1 + 70 * 3}{1+2+3+1+3}",font_size=50)
             sr6=SurroundingRectangle(text6[0],color=YELLOW, buff=MED_LARGE_BUFF)
             mobj6= VGroup(VGroup(sr6, text6)).arrange(UP)
             self.add(mobj6)
             self.play(Create(mobj6))
            self.wait(15)
             self.play(FadeOut(mobj6))
             text7=MathTex(r"mean=\frac{93+ 192 + 255 + 88 + 210}{10}",font_size=50)
             sr7=SurroundingRectangle(text6[0],color=YELLOW, buff=MED_LARGE_BUFF)
             mobj7= VGroup(VGroup(sr7, text7)).arrange(UP)
             self.add(mobj7)
             self.play(Create(mobj7))
             self.wait(8)
             self.play(FadeOut(mobj7))
             text8=MathTex(r"mean=\frac{838}{10}",font_size=50)
             sr8=SurroundingRectangle(text8[0],color=YELLOW, buff=MED_LARGE_BUFF)
             mobj8= VGroup(VGroup(sr8, text8)).arrange(UP)
             self.add(mobj8)
             self.play(Create(mobj8))
             self.wait(5)
             self.play(FadeOut(mobj8))
             text9=MathTex(r"mean=83.80",font_size=50)
             sr9=SurroundingRectangle(text9[0],color=YELLOW, buff=MED_LARGE_BUFF)
             mobj9= VGroup(VGroup(sr9, text9)).arrange(UP)
             self.add(mobj9)
             self.play(Create(mobj9))
             self.wait(4)
             self.play(FadeOut(mobj9))
             self.play(FadeOut(mobj4))

Video Output

Leave a Comment

Your email address will not be published. Required fields are marked *

©Postnetwork-All rights reserved.