티스토리 뷰
Computer/3B1B 따라잡기 with ManimLibrary
[3B1B따라잡기 with Manim!][1일 1마님] 3. NumberPlane / get_area / get_riemann_rectangles / Line() / c2p
벼랑끝과학자 2023. 5. 29. 04:331일 1마님 시리즈는 예제 코드를 하루에 하나씩 따라하면서 마님 라이브러리 사용에 익숙해지기 위해 만든 시리즈입니다! 간단하게 코드 + 코드 리뷰 + 실행 결과만 작성합니다!
class Graphing(Scene):
def construct(self):
my_plane = NumberPlane(x_range= [-6,6], x_length=5,
y_range= [-8,8], y_length=6)
my_plane.shift(LEFT * 2)
my_function = my_plane.plot(lambda x : 0.1*(x-5)*x*(x+5), x_range=[-6,6], color=GREEN)
area = my_plane.get_area(graph = my_function, x_range=[-5,5], color=[BLUE,YELLOW,GREEN])
area2 = my_plane.get_riemann_rectangles(graph = my_function, dx=0.1, x_range=[-5,5], color=[BLUE,YELLOW,GREEN])
T1 = Tex("get area").next_to(area, RIGHT, buff=1)
T2 = Tex("get riemann rectangles").next_to(area2, RIGHT, buff=1)
VG1 = VGroup(area, T1)
VG2 = VGroup(area2, T2)
label = MathTex("f(x)=0.1(x-5)x(x+5)").next_to(my_plane, UP, buff=0.4)
horiz_line = Line(start = my_plane.c2p(6, my_function.underlying_function(-4)),
end = my_plane.c2p(-6, my_function.underlying_function(-4)),
stroke_color=RED, stroke_width=3)
T3 = MathTex("f(x) = f(-4)").next_to(horiz_line, buff=0.3)
VG3 = VGroup(horiz_line, T3)
self.play(DrawBorderThenFill(my_plane))
self.wait(1)
self.play(FadeIn(my_function), Write(label), run_time=2)
self.wait(1)
self.play(FadeIn(VG1))
self.wait(3)
self.play(FadeOut(VG1))
self.wait(2)
self.play(FadeIn(VG2))
self.wait(3)
self.play(FadeOut(T2))
self.play(Create(VG3))
self.wait(3)
- NumberPlane을 이용해서 2차원 좌표계를 생성할 수 있음
- .add_coordinates()를 이용해서 좌표계 위에 숫자까지 표현할 수 있음
- .shift를 이용해 위치 조정 가능
- 만든 좌표계 변수(my_plane)에 plot 메소드를 이용해서 원하는 형태의 그래프를 그릴 수 있음 그래프는 lambda 함수 이용
- 만든 좌표계 변수(my_plane)에 get_area 메소드를 이용해서 특정 그래프의 면적을 그릴 수 있음
- 특히 get_riemann_rectangles() 메소드를 이용하면 적분을 표현할 수 있음
- Tex()를 이용해 일반적인 문자 표현 가능. Tex로 표현하지 못하는 특수문자들 조심할 것
- VGroup을 통해 grouping가능
- MathTex()는 Tex와 달리 수식을 입력하기 위해 사용
- Line()은 말 그대로 선을 그림, start와 end point를 지정해야함.
- c2p는 좌표계(c)로부터 점(p)을 따올 때 사용함. 여기서는 start와 end 좌표를 얻기 위해 사용함
- .underlying_function은 확실한 사용법은 모르겠지만 주로 my_function처럼 plot()함수로 그린 함수에 x값을 전달해서 그 결과값을 얻을 때 사용함.
'Computer > 3B1B 따라잡기 with ManimLibrary' 카테고리의 다른 글
[3B1B따라잡기 with Manim!][1일 1마님] 5. VectorScene (0) | 2023.05.30 |
---|---|
[3B1B따라잡기 with Manim!][1일 1마님] 4. ValueTracker / PolarPlane / ParametricFunction / LaggedStart / set_value (0) | 2023.05.30 |
[3B1B따라잡기 with Manim!][1일 1마님] 2. Axes.plot (0) | 2023.05.27 |
[3B1B 따라잡기 with Manim] 7. Applying Updater and ValueTrackers to Graphing Scene (0) | 2023.05.18 |
[3B1B따라잡기 with Manim!][1일 1마님] 1. lag_ratio (0) | 2023.05.18 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- Manimlibrary
- vae
- MLE
- marginal likelihood
- 백준
- 인공지능
- elementry matrix
- 오일석기계학습
- 파이썬
- 최대우도추정
- 제한볼츠만머신
- 이왜안
- 3B1B따라잡기
- ai인공지능
- manimtutorial
- eigenvalue
- 베이즈정리
- MorganCircularfingerprint
- variational autoencoder
- kld
- eigenvector
- 선형대수
- manim library
- Matrix algebra
- ai신약개발
- 기계학습
- 3b1b
- kl divergence
- MatrixAlgebra
- manim
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함