This commit is contained in:
LinlyBoi
2023-12-18 20:58:14 +02:00
commit a7f38094f4
6 changed files with 575 additions and 0 deletions

352
bar-chart-race.org Normal file
View File

@@ -0,0 +1,352 @@
#+title: Bar Chart Race
* Initial imports
:PROPERTIES:
:header-args: :session barChart :results output :exports both
:END:
#+BEGIN_SRC python
import numpy as np
print("imported!")
#+END_SRC
#+RESULTS:
: imported!
* Loading the Dataset
:PROPERTIES:
:header-args: :session barChart :results output
:END:
#+BEGIN_SRC python
from pathlib import Path
file_name = Path('Sweeteners-Consumption.csv')
root_folder = Path('data')
file_path = root_folder / file_name
print(file_path)
#+END_SRC
#+RESULTS:
: data/Sweeteners-Consumption.csv
#+BEGIN_SRC python
import pandas as pd
dataFrame = pd.read_csv(file_path, header=0, index_col="Calendar Year")
# dataFrame = dataFrame.set_index('Calendar Year')
dataFrame = dataFrame.drop('Total Sweeteners' ,axis=1)
#+END_SRC
#+RESULTS:
#+BEGIN_SRC python :results output table
print(dataFrame.head(10))
#+END_SRC
#+RESULTS:
#+begin_example
Raw Sugar Refined Sugar High-corn ... Total Honey Other Syrups
Calendar Year ...
1966 10235 9565 0 ... 1367 98 69
1967 10474 9789 3 ... 1415 89 50
1968 10656 9959 15 ... 1489 90 70
1969 10950 10234 33 ... 1553 101 61
1970 11163 10433 56 ... 1629 103 51
1971 11345 10603 86 ... 1731 93 52
1972 11487 10736 121 ... 1863 105 52
1973 11429 10681 218 ... 2092 95 53
1974 10945 10229 295 ... 2262 75 43
1975 10302 9628 527 ... 2515 108 43
[10 rows x 8 columns]
#+end_example
* Barchart animation
:PROPERTIES:
:header-args: :session barChart :results output
:END:
#+BEGIN_SRC python
print(dataFrame.iloc[0].to_list())
#+END_SRC
#+RESULTS:
: [10235, 9565, 0, 952, 415, 1367, 98, 69]
#+BEGIN_SRC python :results none
from manim import *
class AnimatedBarChart(Scene):
def construct(self):
bar_names = [
'Raw Sugar','Refined Sugar','High-corn','Glucose','Dextrose','Total Corn','Honey','Other',
]
self.camera.background_color = WHITE
config.renderer='cairo'
config.quality='low_quality'
chart = BarChart(
values = dataFrame.iloc[0].to_list(),
bar_names=bar_names,
y_range=[0,13000, 1000],
y_length=7.0,
x_length=10,
x_axis_config={
"font_size":20,
'label_direction':DOWN,
# 'stroke_color' : RED,
# 'font_color' : BLACK,
# 'color':BLACK
},
y_axis_config={
"font_size":25,
},
axis_config = {
'color':BLACK,
# 'label_color':RED,
'tip_shape': StealthTip,
}
)
#==================================
# this section is to set the axis tick color. The best solution I found was the following for loops
# from this reddit post:
# https://www.reddit.com/r/manim/comments/x7iqzp/colors_of_axis_text_for_barchart/
for tick in chart.get_x_axis():
tick.set_color(BLACK)
for tick in chart.get_y_axis():
tick.set_color(BLACK)
#==================================
current_year =dataFrame.index[0]
date_text = Integer(
number=current_year,
group_with_commas=False,
).set_color(BLACK).scale(2.5)
date_text.move_to(UP*3)
date_text.add_updater(lambda d: d.set_value(current_year))
self.add(chart, date_text)
for i, row in enumerate(dataFrame.itertuples()):
weights = list(row[1:]) #first item is the date
current_year = row[0]
if i == 0:
continue
# elif i > 5: #comment out to render the full animation
# break
self.play(chart.animate.change_bar_values(weights),
# date_text.animate.become(new_date, match_center=True, match_height=True),
rate_func=linear,
run_time=0.7)
scene = AnimatedBarChart()
scene.render()
#+END_SRC
#+RESULTS:
#+begin_example
Animation 0: Create(Tex('1966')): 0% 0/60 [00:00<?, ?it/s]
Animation 0: Create(Tex('1966')): 12% 7/60 [00:00<00:00, 60.84it/s]
Animation 0: Create(Tex('1966')): 27% 16/60 [00:00<00:00, 75.21it/s]
Animation 0: Create(Tex('1966')): 43% 26/60 [00:00<00:00, 82.63it/s]
Animation 0: Create(Tex('1966')): 58% 35/60 [00:00<00:00, 82.93it/s]
Animation 0: Create(Tex('1966')): 73% 44/60 [00:00<00:00, 78.72it/s]
Animation 0: Create(Tex('1966')): 87% 52/60 [00:00<00:00, 56.87it/s]
Animation 0: Create(Tex('1966')): 100% 60/60 [00:00<00:00, 62.10it/s]
[12/12/23 00:58:18] INFO Animation 0 : Partial scene_file_writer.py:527
movie file written in
'/home/linly/Code/Diabetus
-History/media/videos/1080
p60/partial_movie_files/An
imatedBarChart/2621265332_
1392792357_2153479704.mp4'
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 0% 0/48 [00:00<?, ?it/s]
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 6% 3/48 [00:00<00:02, 21.05it/s]
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 12% 6/48 [00:00<00:01, 21.11it/s]
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 19% 9/48 [00:00<00:01, 21.12it/s]
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 25% 12/48 [00:00<00:01, 21.08it/s]
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 31% 15/48 [00:00<00:01, 21.03it/s]
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 38% 18/48 [00:00<00:01, 21.02it/s]
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 44% 21/48 [00:00<00:01, 21.07it/s]
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 50% 24/48 [00:01<00:01, 21.00it/s]
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 56% 27/48 [00:01<00:01, 21.00it/s]
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 62% 30/48 [00:01<00:00, 20.96it/s]
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 69% 33/48 [00:01<00:00, 20.78it/s]
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 75% 36/48 [00:01<00:00, 20.68it/s]
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 81% 39/48 [00:01<00:00, 20.57it/s]
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 88% 42/48 [00:02<00:00, 20.48it/s]
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 94% 45/48 [00:02<00:00, 20.42it/s]
Animation 1: _MethodAnimation(BarChart of 3 submobjects), etc.: 100% 48/48 [00:02<00:00, 20.42it/s]
[12/12/23 00:58:22] INFO Animation 1 : Partial scene_file_writer.py:527
movie file written in
'/home/linly/Code/Diabetus
-History/media/videos/1080
p60/partial_movie_files/An
imatedBarChart/4272032393_
266712404_928210545.mp4'
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 0% 0/48 [00:00<?, ?it/s]
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 6% 3/48 [00:00<00:02, 21.06it/s]
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 12% 6/48 [00:00<00:01, 21.09it/s]
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 19% 9/48 [00:00<00:01, 21.07it/s]
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 25% 12/48 [00:00<00:01, 20.91it/s]
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 31% 15/48 [00:00<00:01, 20.90it/s]
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 38% 18/48 [00:00<00:01, 20.90it/s]
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 44% 21/48 [00:01<00:01, 20.90it/s]
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 50% 24/48 [00:01<00:01, 20.94it/s]
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 56% 27/48 [00:01<00:01, 20.90it/s]
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 62% 30/48 [00:01<00:00, 20.85it/s]
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 69% 33/48 [00:01<00:00, 20.63it/s]
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 75% 36/48 [00:01<00:00, 20.52it/s]
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 81% 39/48 [00:01<00:00, 20.42it/s]
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 88% 42/48 [00:02<00:00, 20.35it/s]
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 94% 45/48 [00:02<00:00, 20.35it/s]
Animation 2: _MethodAnimation(BarChart of 3 submobjects), etc.: 100% 48/48 [00:02<00:00, 20.33it/s]
[12/12/23 00:58:26] INFO Animation 2 : Partial scene_file_writer.py:527
movie file written in
'/home/linly/Code/Diabetus
-History/media/videos/1080
p60/partial_movie_files/An
imatedBarChart/4272032393_
206340557_928210545.mp4'
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 0% 0/48 [00:00<?, ?it/s]
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 6% 3/48 [00:00<00:02, 21.05it/s]
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 12% 6/48 [00:00<00:02, 20.95it/s]
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 19% 9/48 [00:00<00:01, 20.94it/s]
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 25% 12/48 [00:00<00:01, 20.89it/s]
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 31% 15/48 [00:00<00:01, 20.91it/s]
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 38% 18/48 [00:00<00:01, 20.84it/s]
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 44% 21/48 [00:01<00:01, 20.85it/s]
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 50% 24/48 [00:01<00:01, 20.87it/s]
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 56% 27/48 [00:01<00:01, 20.88it/s]
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 62% 30/48 [00:01<00:00, 20.71it/s]
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 69% 33/48 [00:01<00:00, 20.54it/s]
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 75% 36/48 [00:01<00:00, 20.45it/s]
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 81% 39/48 [00:01<00:00, 20.36it/s]
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 88% 42/48 [00:02<00:00, 20.31it/s]
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 94% 45/48 [00:02<00:00, 20.24it/s]
Animation 3: _MethodAnimation(BarChart of 3 submobjects), etc.: 100% 48/48 [00:02<00:00, 20.22it/s]
[12/12/23 00:58:30] INFO Animation 3 : Partial scene_file_writer.py:527
movie file written in
'/home/linly/Code/Diabetus
-History/media/videos/1080
p60/partial_movie_files/An
imatedBarChart/4272032393_
4101352158_928210545.mp4'
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 0% 0/48 [00:00<?, ?it/s]
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 6% 3/48 [00:00<00:02, 20.95it/s]
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 12% 6/48 [00:00<00:01, 21.02it/s]
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 19% 9/48 [00:00<00:01, 21.02it/s]
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 25% 12/48 [00:00<00:01, 20.98it/s]
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 31% 15/48 [00:00<00:01, 20.96it/s]
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 38% 18/48 [00:00<00:01, 20.93it/s]
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 44% 21/48 [00:01<00:01, 20.95it/s]
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 50% 24/48 [00:01<00:01, 21.00it/s]
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 56% 27/48 [00:01<00:01, 21.00it/s]
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 62% 30/48 [00:01<00:00, 20.76it/s]
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 69% 33/48 [00:01<00:00, 20.61it/s]
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 75% 36/48 [00:01<00:00, 20.51it/s]
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 81% 39/48 [00:01<00:00, 20.41it/s]
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 88% 42/48 [00:02<00:00, 20.36it/s]
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 94% 45/48 [00:02<00:00, 20.31it/s]
Animation 4: _MethodAnimation(BarChart of 3 submobjects), etc.: 100% 48/48 [00:02<00:00, 20.26it/s]
[12/12/23 00:58:34] INFO Animation 4 : Partial scene_file_writer.py:527
movie file written in
'/home/linly/Code/Diabetus
-History/media/videos/1080
p60/partial_movie_files/An
imatedBarChart/4272032393_
3354045674_928210545.mp4'
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 0% 0/48 [00:00<?, ?it/s]
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 6% 3/48 [00:00<00:02, 21.13it/s]
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 12% 6/48 [00:00<00:01, 21.07it/s]
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 19% 9/48 [00:00<00:01, 21.03it/s]
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 25% 12/48 [00:00<00:01, 21.00it/s]
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 31% 15/48 [00:00<00:01, 20.95it/s]
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 38% 18/48 [00:00<00:01, 20.94it/s]
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 44% 21/48 [00:01<00:01, 20.90it/s]
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 50% 24/48 [00:01<00:01, 20.88it/s]
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 56% 27/48 [00:01<00:01, 20.88it/s]
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 62% 30/48 [00:01<00:00, 20.66it/s]
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 69% 33/48 [00:01<00:00, 20.51it/s]
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 75% 36/48 [00:01<00:00, 20.43it/s]
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 81% 39/48 [00:01<00:00, 20.37it/s]
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 88% 42/48 [00:02<00:00, 20.35it/s]
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 94% 45/48 [00:02<00:00, 20.26it/s]
Animation 5: _MethodAnimation(BarChart of 3 submobjects), etc.: 100% 48/48 [00:02<00:00, 20.13it/s]
[12/12/23 00:58:38] INFO Animation 5 : Partial scene_file_writer.py:527
movie file written in
'/home/linly/Code/Diabetus
-History/media/videos/1080
p60/partial_movie_files/An
imatedBarChart/4272032393_
401898931_928210545.mp4'
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 0% 0/48 [00:00<?, ?it/s]
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 6% 3/48 [00:00<00:02, 20.78it/s]
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 12% 6/48 [00:00<00:02, 20.94it/s]
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 19% 9/48 [00:00<00:01, 20.96it/s]
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 25% 12/48 [00:00<00:01, 20.99it/s]
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 31% 15/48 [00:00<00:01, 21.00it/s]
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 38% 18/48 [00:00<00:01, 21.00it/s]
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 44% 21/48 [00:01<00:01, 20.97it/s]
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 50% 24/48 [00:01<00:01, 20.94it/s]
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 56% 27/48 [00:01<00:01, 20.96it/s]
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 62% 30/48 [00:01<00:00, 20.81it/s]
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 69% 33/48 [00:01<00:00, 20.65it/s]
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 75% 36/48 [00:01<00:00, 20.56it/s]
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 81% 39/48 [00:01<00:00, 20.46it/s]
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 88% 42/48 [00:02<00:00, 20.42it/s]
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 94% 45/48 [00:02<00:00, 20.36it/s]
Animation 6: _MethodAnimation(BarChart of 3 submobjects), etc.: 100% 48/48 [00:02<00:00, 20.34it/s]
[12/12/23 00:58:42] INFO Animation 6 : Partial scene_file_writer.py:527
movie file written in
'/home/linly/Code/Diabetus
-History/media/videos/1080
p60/partial_movie_files/An
imatedBarChart/4272032393_
621825198_928210545.mp4'
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 0% 0/48 [00:00<?, ?it/s]
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 6% 3/48 [00:00<00:02, 20.82it/s]
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 12% 6/48 [00:00<00:02, 20.94it/s]
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 19% 9/48 [00:00<00:01, 20.93it/s]
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 25% 12/48 [00:00<00:01, 20.91it/s]
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 31% 15/48 [00:00<00:01, 20.89it/s]
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 38% 18/48 [00:00<00:01, 20.83it/s]
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 44% 21/48 [00:01<00:01, 20.84it/s]
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 50% 24/48 [00:01<00:01, 20.86it/s]
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 56% 27/48 [00:01<00:01, 20.87it/s]
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 62% 30/48 [00:01<00:00, 20.69it/s]
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 69% 33/48 [00:01<00:00, 20.52it/s]
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 75% 36/48 [00:01<00:00, 20.42it/s]
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 81% 39/48 [00:01<00:00, 20.36it/s]
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 88% 42/48 [00:02<00:00, 20.35it/s]
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 94% 45/48 [00:02<00:00, 20.31it/s]
Animation 7: _MethodAnimation(BarChart of 3 submobjects), etc.: 100% 48/48 [00:02<00:00, 20.28it/s]
[12/12/23 00:58:46] INFO Animation 7 : Partial scene_file_writer.py:527
movie file written in
'/home/linly/Code/Diabetus
-History/media/videos/1080
p60/partial_movie_files/An
imatedBarChart/4272032393_
1632555210_928210545.mp4'