From cd14dea021c3b7fd45c80f44c9916028e44944d8 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Wed, 15 Jan 2020 18:00:43 -0800 Subject: [PATCH] Beginning beta project --- from_3b1b/active/bayes/beta.py | 83 ++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 from_3b1b/active/bayes/beta.py diff --git a/from_3b1b/active/bayes/beta.py b/from_3b1b/active/bayes/beta.py new file mode 100644 index 00000000..143ca5b7 --- /dev/null +++ b/from_3b1b/active/bayes/beta.py @@ -0,0 +1,83 @@ +from manimlib.imports import * + +OUTPUT_DIRECTORY = "bayes/beta" + + +class BarChart(Axes): + CONFIG = { + "x_min": 0, + "x_max": 10, + "y_min": 0, + "y_max": 1, + "axis_config": { + "include_tip": False, + }, + "y_axis_config": { + "tick_frequency": 0.2, + }, + "height": 5, + "width": 10, + "y_axis_numbers_to_show": range(20, 120, 20), + "y_axis_label_height": 0.25, + "include_h_lines": True, + "h_line_style": { + "stroke_width": 1, + "stroke_color": LIGHT_GREY, + } + } + + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.resize() + self.center() + self.add_y_axis_labels() + if self.include_h_lines: + self.add_h_lines() + self.add_bars() + + # Initializing methods + def resize(self): + self.x_axis.set_width( + self.width, + stretch=True, + about_point=self.c2p(0, 0), + ) + self.y_axis.set_height( + self.height, + stretch=True, + about_point=self.c2p(0, 0), + ) + + def add_y_axis_labels(self): + labels = VGroup() + for value in self.y_axis_numbers_to_show: + label = Integer(value, unit="\\%") + label.set_height(self.y_axis_label_height) + label.next_to(self.y_axis.n2p(0.01 * value), LEFT) + labels.add(label) + self.y_axis_labels = labels + self.y_axis.add(labels) + return self + + def add_h_lines(self): + self.h_lines = VGroup() + for tick in self.y_axis.tick_marks: + line = Line(**self.h_line_style) + line.match_width(self.x_axis) + line.move_to(tick.get_center(), LEFT) + self.h_lines.add(line) + self.add(self.h_lines) + + def add_bars(self): + pass + + # Bar manipulations + + + +# Scenes +class BarChartTest(Scene): + def construct(self): + bar_chart = BarChart() + bar_chart.to_edge(DOWN) + self.add(bar_chart)