From c102e97fef8b0940ac2220473815d21131107d28 Mon Sep 17 00:00:00 2001 From: davidportlouis Date: Wed, 30 Jun 2021 22:51:00 +0530 Subject: [PATCH] added docstrings for functions --- utils/plot.py | 108 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 95 insertions(+), 13 deletions(-) diff --git a/utils/plot.py b/utils/plot.py index a89ca878..adebb5c0 100644 --- a/utils/plot.py +++ b/utils/plot.py @@ -2,14 +2,38 @@ import matplotlib.pyplot as plt import seaborn as sns -def cscatter(filename: str, xCol: str, yCol: str, - dateCol:str = None, maskCol: str = None, - type_: str = None, color: str = None, - xLabel: str = None, yLabel: str = None, figTitle: str = None, - figWidth: int = 26, figHeight: int = 7) -> None: +def cscatter(filename: str, + xCol: str, + yCol: str, + dateCol:str = None, + maskCol: str = None, + type_: str = None, + color: str = None, + xLabel: str = None, + yLabel: str = None, + figTitle: str = None, + figWidth: int = 26, + figHeight: int = 7) -> None: """ - creates a scatter plot of size figWidth & figHeight, named - figTitle and saves it. + Creates a scatter plot of size figWidth & figHeight, named figTitle and saves it. + + Parameters: + filename (str): Name of the dataset to load. + xCol (str): Name of the feature in dataset to plot against X axis. + yCol (str): Name of the feature in dataset to plot against Y axis. + dateCol (str): Name of the feature containing dates to parse; default to None. + maskCol (str): Name of the feature in dataset to mask; defaults to None. + type_ (str): Name of the feature in dataset to use for masking; defaults to None. + color (str): Name of the feature in dataset to be used for color value in plotting; + defaults to None. + xlabel (str): Label for X axis; defaults to None. + ylabel (str): Label for Y axis; defaults to None. + figTitle (str): Title for the figure to be save; defaults to None. + figWidth (int): Width of the figure; defaults to 26. + figHeight (int): Height of the figure; defaults to 7. + + Returns: + (None): Function does not return anything. """ sns.set(color_codes=True) if dateCol: @@ -34,10 +58,28 @@ def cscatter(filename: str, xCol: str, yCol: str, plt.savefig(f"{figTitle}.png") plt.close() -def cbarplot(filename: str, x: str, y: str, dateCol: str = None, figTitle: str = None, figWidth: int = 5, figHeight: int = 7) -> None: +def cbarplot(filename: str, + x: str, + y: str, + dateCol: str = None, + figTitle: str = None, + figWidth: int = 5, + figHeight: int = 7) -> None: """ - Creates a bar plot of size figWidth & figHeight, named - figTitle between x & y. + Creates a bar plot of size figWidth & figHeight, named figTitle between x & y. + + Parameters: + filename (str): Name of the dataset to load. + x (str): Name of the feature in dataset to plot against X axis. + y (str): Name of the feature in dataset to plot against Y axis. + dateCol (str): name of the feature containing dates to parse; default to None. + maskCol (str): name of the feature in dataset to mask; defaults to None. + figTitle (str): Title for the figure to be save; defaults to None. + figWidth (int): Width of the figure; defaults to 5. + figHeight (int): Height of the figure; defaults to 7. + + Returns: + (None): Function does not return anything. """ sns.set(color_codes=True) if dateCol: @@ -50,9 +92,25 @@ def cbarplot(filename: str, x: str, y: str, dateCol: str = None, figTitle: str = plt.savefig(f"{figTitle}.png") plt.close() -def cheatmap(filename: str, cmap: str, annotate: bool, figTitle: str, figWidth: int = 12, figHeight: int = 6) -> None: +def cheatmap(filename: str, + cmap: str, + annotate: bool, + figTitle: str, + figWidth: int = 12, + figHeight: int = 6) -> None: """ Creates a heatmap (correlation map) of the dataset and saves it. + + Parameters: + filename (str): Name of the dataset to load. + cmap (str): Name of the color map to be used for plotting. + annotate (bool): Indicates whether plot should be annotated with correlation values. + figTitle (str): Title for the figure to be save; defaults to None. + figWidth (int): Width of the figure; defaults to 12. + figHeight (int): Height of the figure; defaults to 6. + + Returns: + (None): Function does not return anything. """ sns.set(color_codes=True) df = pd.read_csv(filename) @@ -63,9 +121,21 @@ def cheatmap(filename: str, cmap: str, annotate: bool, figTitle: str, figWidth: plt.savefig(f"{figTitle}.png") plt.close() -def clmplot(filename: str, figTitle: str = None, figWidth: int = 6, figHeight: int = 7) -> None: +def clmplot(filename: str, + figTitle: str = None, + figWidth: int = 6, + figHeight: int = 7) -> None: """ Generates a regression plot on the given dataset and saves it. + + Parameters: + filename (str): Name of the dataset to load. + figTitle (str): Title for the figure to be save; defaults to None. + figWidth (int): Width of the figure; defaults to 6. + figHeight (int): Height of the figure; defaults to 7. + + Returns: + (None): Function does not return anything. """ sns.set(color_codes=True) df = pd.read_csv(filename) @@ -75,9 +145,21 @@ def clmplot(filename: str, figTitle: str = None, figWidth: int = 6, figHeight: i plt.savefig(f"{figTitle}.png") plt.close() -def chistplot(filename: str, figTitle: str = None, figWidth: int = 6, figHeight: int = 4) -> None: +def chistplot(filename: str, + figTitle: str = None, + figWidth: int = 6, + figHeight: int = 4) -> None: """ Generated a histogram on the given dataset and saves it. + + Parameters: + filename (str): Name of the dataset to load. + figTitle (str): Title for the figure to be save; defaults to None. + figWidth (int): Width of the figure; defaults to 6. + figHeight (int): Height of the figure; defaults to 4. + + Returns: + (None): Function does not return anything. """ sns.set(color_codes=True) df = pd.read_csv(filename)