diff --git a/src/Plotter.py b/src/Plotter.py new file mode 100644 index 0000000000000000000000000000000000000000..a63932026ca68be3ddeae51d0d3420edd25d2036 --- /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)