commit a7f38094f477421b33c8f03776dacb3993094d82 Author: LinlyBoi Date: Mon Dec 18 20:58:14 2023 +0200 pog diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9a63a96 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/media/ +/__pycache__/ +/test.py diff --git a/bar-chart-race.org b/bar-chart-race.org new file mode 100644 index 0000000..ad89ee0 --- /dev/null +++ b/bar-chart-race.org @@ -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 100 + files). Therefore, manim + has removed the 14 oldest + file(s). You can change + this behaviour by changing + max_files_cached in + config. + INFO Rendered AnimatedBarChart scene.py:241 + Played 26 animations +#+end_example diff --git a/data/Corn-Daily.csv b/data/Corn-Daily.csv new file mode 100644 index 0000000..4945c41 --- /dev/null +++ b/data/Corn-Daily.csv @@ -0,0 +1,54 @@ +Year,Calory number,teaspoons +1970,2,0.1 +1971,2,0.1 +1972,3,0.2 +1973,6,0.4 +1974,8,0.5 +1975,14,0.9 +1976,20,1.2 +1977,27,1.7 +1978,30,1.9 +1979,41,2.6 +1980,53,3.3 +1981,64,4.0 +1982,74,4.6 +1983,87,5.4 +1984,104,6.5 +1985,126,7.9 +1986,127,8.0 +1987,133,8.3 +1988,136,8.5 +1989,134,8.4 +1990,138,8.6 +1991,141,8.8 +1992,145,9.1 +1993,152,9.5 +1994,158,9.9 +1995,165,10.3 +1996,169,10.6 +1997,178,11.1 +1998,183,11.4 +1999,188,11.7 +2000,179,11.2 +2001,178,11.1 +2002,179,11.2 +2003,174,10.9 +2004,171,10.7 +2005,170,10.6 +2006,167,10.5 +2007,161,10.1 +2008,152,9.5 +2009,144,9.0 +2010,141,8.8 +2011,135,8.5 +2012,133,8.3 +2013,127,8.0 +2014,128,8.0 +2015,125,7.8 +2016,121,7.6 +2017,118,7.4 +2018,114,7.1 +2019,111,7.0 +2020,111,7.0 +2021,110,6.9 +2022,110,6.9 diff --git a/data/Other-Daily.csv b/data/Other-Daily.csv new file mode 100644 index 0000000..555eb8f --- /dev/null +++ b/data/Other-Daily.csv @@ -0,0 +1,54 @@ +Year,number,teaspoons +1970,48,3.0 +1971,49,3.1 +1972,52,3.2 +1973,54,3.4 +1974,55,3.5 +1975,56,3.5 +1976,55,3.4 +1977,54,3.4 +1978,54,3.4 +1979,53,3.3 +1980,50,3.1 +1981,50,3.1 +1982,50,3.1 +1983,51,3.2 +1984,51,3.2 +1985,52,3.2 +1986,53,3.3 +1987,53,3.3 +1988,55,3.4 +1989,50,3.1 +1990,53,3.3 +1991,54,3.4 +1992,56,3.5 +1993,59,3.7 +1994,59,3.7 +1995,61,3.8 +1996,64,4.0 +1997,65,4.1 +1998,64,4.0 +1999,62,3.9 +2000,59,3.7 +2001,59,3.7 +2002,59,3.7 +2003,57,3.6 +2004,58,3.6 +2005,58,3.6 +2006,53,3.3 +2007,52,3.3 +2008,51,3.2 +2009,49,3.1 +2010,49,3.1 +2011,48,3.0 +2012,47,3.0 +2013,46,2.9 +2014,48,3.0 +2015,48,3.0 +2016,47,3.0 +2017,51,3.2 +2018,50,3.2 +2019,50,3.1 +2020,49,3.1 +2021,50,3.1 +2022,50,3.1 diff --git a/data/Sugar-Daily.csv b/data/Sugar-Daily.csv new file mode 100644 index 0000000..78237d7 --- /dev/null +++ b/data/Sugar-Daily.csv @@ -0,0 +1,54 @@ +Year,Calory number,teaspoons +1970,284,17.8 +1971,285,17.8 +1972,285,17.8 +1973,281,17.6 +1974,267,16.7 +1975,249,15.5 +1976,260,16.3 +1977,263,16.4 +1978,255,15.9 +1979,249,15.6 +1980,233,14.6 +1981,221,13.8 +1982,205,12.8 +1983,196,12.2 +1984,186,11.6 +1985,175,10.9 +1986,167,10.5 +1987,174,10.9 +1988,173,10.8 +1989,175,10.9 +1990,180,11.2 +1991,178,11.1 +1992,178,11.1 +1993,178,11.1 +1994,181,11.3 +1995,183,11.4 +1996,184,11.5 +1997,184,11.5 +1998,185,11.5 +1999,189,11.8 +2000,182,11.4 +2001,179,11.2 +2002,176,11.0 +2003,170,10.6 +2004,172,10.7 +2005,176,11.0 +2006,174,10.9 +2007,171,10.7 +2008,183,11.4 +2009,177,11.1 +2010,184,11.5 +2011,185,11.6 +2012,186,11.6 +2013,190,11.9 +2014,191,11.9 +2015,193,12.0 +2016,194,12.2 +2017,193,12.0 +2018,191,11.9 +2019,190,11.9 +2020,190,11.9 +2021,194,12.1 +2022,193,12.1 diff --git a/data/Sweeteners-Consumption.csv b/data/Sweeteners-Consumption.csv new file mode 100644 index 0000000..f67663d --- /dev/null +++ b/data/Sweeteners-Consumption.csv @@ -0,0 +1,58 @@ +Calendar Year,Raw Sugar,Refined Sugar,High-corn,Glucose,Dextrose,Total,Honey,Other Syrups,Total Sweeteners +1966,10235,9565,0,952,415,1367,98,69,11099 +1967,10474,9789,3,984,428,1415,89,50,11342 +1968,10656,9959,15,1031,444,1489,90,70,11608 +1969,10950,10234,33,1061,459,1553,101,61,11949 +1970,11163,10433,56,1102,471,1629,103,51,12216 +1971,11345,10603,86,1163,482,1731,93,52,12478 +1972,11487,10736,121,1257,485,1863,105,52,12756 +1973,11429,10681,218,1384,489,2092,95,53,12922 +1974,10945,10229,295,1480,486,2262,75,43,12609 +1975,10302,9628,527,1515,473,2515,108,43,12294 +1976,10893,10180,782,1514,452,2748,100,44,13072 +1977,11099,10373,1057,1517,429,3003,100,44,13519 +1978,10889,10177,1198,1551,410,3159,120,45,13501 +1979,10756,10052,1660,1519,399,3578,117,44,13791 +1980,10189,9522,2158,1472,393,4024,94,50,13690 +1981,9769,9130,2626,1486,390,4501,96,46,13773 +1982,9153,8554,3090,1479,392,4961,104,46,13665 +1983,8812,8236,3655,1523,398,5577,116,47,13975 +1984,8428,7877,4399,1552,408,6359,108,47,14391 +1985,8003,7479,5386,1607,418,7411,104,48,15043 +1986,7731,7225,5498,1632,430,7561,121,50,14957 +1987,8103,7573,5792,1679,441,7912,107,54,15647 +1988,8136,7604,5998,1747,452,8197,104,54,15958 +1989,8304,7761,5960,1587,438,7985,97,52,15895 +1990,8615,8051,6202,1700,455,8358,103,53,16566 +1991,8622,8058,6376,1776,463,8615,116,53,16842 +1992,8748,8175,6643,1943,461,9047,126,20,17368 +1993,8825,8248,7065,2050,481,9596,135,20,17999 +1994,9070,8477,7415,2093,502,10011,126,18,18632 +1995,9258,8652,7781,2176,528,10486,120,36,19294 +1996,9400,8785,8050,2216,537,10803,131,94,19814 +1997,9481,8861,8555,2364,511,11430,129,81,20502 +1998,9594,8966,8885,2358,502,11745,130,81,20921 +1999,9912,9264,9197,2281,488,11966,147,78,21455 +2000,9901,9253,9091,2230,476,11797,157,84,21290 +2001,9839,9195,9098,2205,469,11773,134,142,21245 +2002,9746,9109,9246,2224,473,11942,153,138,21342 +2003,9479,8859,9078,2209,449,11736,146,112,20853 +2004,9678,9045,9017,2292,487,11796,130,96,21067 +2005,10000,9346,9008,2261,481,11750,155,94,21345 +2006,9976,9323,8984,2053,463,11501,167,98,21089 +2007,9914,9265,8717,2067,448,11233,149,94,20740 +2008,10682,9983,8301,2036,419,10756,151,93,20983 +2009,10452,9768,7957,1991,417,10365,141,90,20364 +2010,10961,10244,7831,1956,450,10237,160,104,20745 +2011,11086,10361,7578,1908,446,9932,169,102,20564 +2012,11227,10492,7494,1969,420,9884,174,104,20654 +2013,11542,10787,7243,1903,415,9561,183,111,20642 +2014,11699,10934,7332,1941,472,9745,207,127,21013 +2015,11885,11107,7183,1972,476,9631,207,137,21083 +2016,12081,11291,7036,2001,443,9480,202,105,21079 +2017,12051,11262,6883,2129,481,9493,232,109,21098 +2018,12009,11224,6702,2148,483,9332,218,115,20889 +2019,12027,11240,6578,2162,462,9202,207,125,20774 +2020,12147,11352,6637,2118,464,9220,222,120,20915 +2021,12394,11583,6566,2154,459,9179,242,147,21150 +2022,12392,11581,6572,2149,438,9159,220,161,21121