From c7fbac58e1acc52682d5810246d680805c39113d Mon Sep 17 00:00:00 2001 From: niklasfranz <nf.app@icloud.com> Date: Mon, 10 Jul 2023 18:43:11 +0200 Subject: [PATCH] feat: added Plotter class for plotting --- src/Plotter.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/Plotter.py diff --git a/src/Plotter.py b/src/Plotter.py new file mode 100644 index 0000000..a639320 --- /dev/null +++ b/src/Plotter.py @@ -0,0 +1,15 @@ +import numpy as np +import matplotlib.pyplot as plt +import pandas as pd +from .Dataset import Dataset + +class Plotter: + def __init__(self, dataset: Dataset): + self.df = dataset.get_dataframe() + + def plotCategoricalBarChart(self, category1, category2, title): + ct = pd.crosstab(self.df[category1], self.df[category2]) + ct_percent = ct.apply(lambda r: r/r.sum() * 100, axis=0) # Calculate percentages by row + fig, ax = plt.subplots() + ax.set_title(title) + ct_percent.plot(kind='bar', ax=ax) -- GitLab