Skip to content
Snippets Groups Projects
Commit 66788a30 authored by niklasfranz's avatar niklasfranz
Browse files

refactor: added func documentation

parent 566f8cbe
No related branches found
No related tags found
No related merge requests found
...@@ -10,11 +10,32 @@ class Plotter: ...@@ -10,11 +10,32 @@ class Plotter:
self.ds = dataset self.ds = dataset
self.df = dataset.get_dataframe() self.df = dataset.get_dataframe()
def customize_plot(self, fig, ax, styling_params): def customize_plot(self, fig, ax, styling_params) -> None:
""" customize_plot
Args:
fig (plt.figure.Figure),
ax (plt.axes.Axes),
styling_params (dict)
Returns:
None
"""
if styling_params.get("title"): if styling_params.get("title"):
ax.set_title(styling_params["title"]) ax.set_title(styling_params["title"])
def distribution_plot(self, target): def distribution_plot(self, target) -> None:
""" plot a distribution plot.
Args:
target (str, must be present as a column in the dataset),
styling_params (dict)
Returns:
None
"""
grouped_data = self.df.groupby(target).size() grouped_data = self.df.groupby(target).size()
plt.barh(grouped_data.index, grouped_data.values) plt.barh(grouped_data.index, grouped_data.values)
print( print(
...@@ -28,7 +49,18 @@ class Plotter: ...@@ -28,7 +49,18 @@ class Plotter:
def plot_categorical_bar_chart( def plot_categorical_bar_chart(
self, category1, category2, styling_params={} self, category1, category2, styling_params={}
): ) -> None:
""" plot a categorical bar chart.
Args:
category1 (str, must be present as a column in the dataset),
category2 (str, must be present as a column in the dataset),
styling_params (dict)
Returns:
None
"""
ct = pd.crosstab(self.df[category1], self.df[category2]) ct = pd.crosstab(self.df[category1], self.df[category2])
# Calculate percentages by row # Calculate percentages by row
ct_percent = ct.apply(lambda r: r / r.sum() * 100, axis=0) ct_percent = ct.apply(lambda r: r / r.sum() * 100, axis=0)
...@@ -36,14 +68,39 @@ class Plotter: ...@@ -36,14 +68,39 @@ class Plotter:
self.customize_plot(fig, ax, styling_params) self.customize_plot(fig, ax, styling_params)
ct_percent.plot(kind="bar", ax=ax) ct_percent.plot(kind="bar", ax=ax)
def plot_categorical_boxplot(self, target, category, styling_params={}): def plot_categorical_boxplot(
self, target, category, styling_params={}
) -> None:
""" plot a categorical boxplot.
Args:
target (str, must be present as a column in the dataset),
category (str, must be present as a column in the dataset),
styling_params (dict)
Returns:
None
"""
fig, ax = plt.subplots() fig, ax = plt.subplots()
self.customize_plot(fig, ax, styling_params) self.customize_plot(fig, ax, styling_params)
sns.boxplot(x=category, y=target, data=self.df, palette="rainbow") sns.boxplot(x=category, y=target, data=self.df, palette="rainbow")
def plot_categorical_histplot( def plot_categorical_histplot(
self, target, category, styling_params={}, bins=30 self, target, category, styling_params={}, bins=30
): ) -> None:
""" plot a categorical hisplot.
Args:
target (str, must be present as a column in the dataset),
category (str, must be present as a column in the dataset),
styling_params (dict)
Returns:
None
"""
uniques = self.ds.get_unique_column_values(category) uniques = self.ds.get_unique_column_values(category)
fig, ax = plt.subplots() fig, ax = plt.subplots()
self.customize_plot(fig, ax, styling_params) self.customize_plot(fig, ax, styling_params)
...@@ -57,7 +114,18 @@ class Plotter: ...@@ -57,7 +114,18 @@ class Plotter:
alpha=0.5, alpha=0.5,
) )
def plot_scatterplot(self, target1, target2, styling_params={}): def plot_scatterplot(self, target1, target2, styling_params={}) -> None:
""" plot a scatterplot.
Args:
target1 (str, must be present as a column in the dataset),
target2 (str, must be present as a column in the dataset),
styling_params (dict)
Returns:
None
"""
fig, ax = plt.subplots() fig, ax = plt.subplots()
self.customize_plot(fig, ax, styling_params) self.customize_plot(fig, ax, styling_params)
ax.scatter(self.df[target1], self.df[target2]) ax.scatter(self.df[target1], self.df[target2])
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment