def test_save_all_figures():
    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(df_nan)
    data.builder = builder
    data.visual_missing_data()
    builder.figure.save_all_figures(folder="tmp")
    assert len(list(Path("tmp").glob("*.png"))) == 4
Beispiel #2
0
    def plotdata(
        df: pd.DataFrame,
        plot_type: str = "lineplot",
        dark_mode: bool = False,
        grid: bool = False,
        figsize: tuple = (12, 8),
        dpi: int = 300,
        save_fig: bool = True,
        show_fig: bool = False,
        x_label: str = None,
        y_label: str = None,
        hue: str = None,
        palette: Union[str, list, dict] = None,
        folder: str = None,
        **kwargs,
    ) -> None:
        """Plotting all pandas dataframes as `oneliner`.

        !!! warning
            All defined functions of`ai2business.visualization.data_visualization` will be
            called via `getattr`, so be sure that the `class DataVisualization` function
            is typed correctly.

        Args:
            df (pd.DataFrame): [description]
            plot_type (str, optional): [description]. Defaults to "lineplot".
            dark_mode (bool, optional): [description]. Defaults to False.
            grid (bool, optional): [description]. Defaults to False.
            figsize (tuple, optional): [description]. Defaults to (12, 8).
            dpi (int, optional): [description]. Defaults to 300.
            save_fig (bool, optional): [description]. Defaults to True.
            show_fig (bool, optional): [description]. Defaults to False.
            x_label (str, optional): [description]. Defaults to None.
            y_label (str, optional): [description]. Defaults to None.
            hue (str, optional): [description]. Defaults to None.
            palette (Union[str, list, dict], optional): [description]. Defaults to None.
            folder (str, optional): [description]. Defaults to None.
        """
        data = data_visualization.DataVisualization()
        builder = data_visualization.DesignerDataVisualization(
            df,
            dark_mode=dark_mode,
            grid=grid,
            figsize=figsize,
            dpi=dpi,
            x_label=x_label,
            y_label=y_label,
            hue=hue,
            palette=palette,
        )
        data.builder = builder
        try:
            getattr(data, plot_type.lower())(**kwargs)
        except AttributeError as exc:
            print(f"ERROR: {exc}")
        if save_fig:
            builder.figure.save_all_figures(folder=folder)
        if show_fig:
            plt.show()
Beispiel #3
0
def test_lineplot_whitegrid():
    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(iris_dataframe, grid=True)
    data.builder = builder
    data.lineplot()
    folder = "tmp_whitegrid"
    builder.figure.save_all_figures(folder=folder)
    assert len(list(Path(f"{folder}").glob("*.png"))) == 1
def test_violinplot():
    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(
        df_dict_fruits["get_interest_over_time"], )
    data.builder = builder
    data.violinplot()
    folder = f"{test_violinplot.__name__}"
    builder.figure.save_all_figures(folder=folder)
    assert len(list(Path(f"{folder}").glob("*.png"))) == 1
def test_visual_missing_data():
    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(df_nan)
    data.builder = builder
    data.visual_missing_data()
    result = builder.figure.return_product
    for i, key in enumerate(result.keys()):
        result[key].savefig(Path(f"./test_visual_missing_data_{key}.png"))

    assert len(list(Path(".").glob("test_visual_missing_data_*.png"))) == i + 1
def test_histogramplot():
    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(
        df_dict_fruits["get_interest_over_time"],
        x_label="apple",
        hue="super market")
    data.builder = builder
    data.histogramplot(multiple="stack", log_scale=True)
    folder = f"{test_histogramplot.__name__}"
    builder.figure.save_all_figures(folder=folder)
    assert len(list(Path(f"{folder}").glob("*.png"))) == 1
def test_pairmap_complex():
    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(
        df_dict_fruits["get_interest_over_time"].drop(columns="isPartial"),
        x_label="apple",
        y_label="pineapple",
    )
    data.builder = builder
    data.pairmap(complex=True)
    folder = f"{test_pairmap_complex.__name__}"
    builder.figure.save_all_figures(folder=folder)
    assert len(list(Path(f"{folder}").glob("*.png"))) == 1
def test_correlation_2():
    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(
        df_dict_fruits["get_interest_over_time"],
        x_label="apple",
        y_label="pineapple",
    )
    data.builder = builder
    data.correlationmap(diagonal=True)
    folder = f"{test_correlation_2.__name__}"
    builder.figure.save_all_figures(folder=folder)
    assert len(list(Path(f"{folder}").glob("*.png"))) == 1
def test_list_product_parts():
    # Test return of products
    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(df_nan)
    data.builder = builder
    data.visual_missing_data()
    result = builder.figure.list_product_parts

    assert (
        result
        == "Product parts: get_nullity_matrix, get_nullity_bar, get_nullity_heatmap, get_nullity_dendrogram"
    )
def test_residualplot():
    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(
        df_dict_fruits["get_interest_over_time"],
        x_label="apple",
        y_label="super market",
    )
    data.builder = builder
    data.residualplot(lowess=True, color="b")
    folder = f"{test_residualplot.__name__}"
    builder.figure.save_all_figures(folder=folder)
    assert len(list(Path(f"{folder}").glob("*.png"))) == 1
def test_hexagonplot():
    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(
        df_dict_fruits["get_interest_over_time"],
        x_label="apple",
        y_label="pineapple",
    )
    data.builder = builder
    data.hexagonplot(color="#4CB391")
    folder = f"{test_hexagonplot.__name__}"
    builder.figure.save_all_figures(folder=folder)
    assert len(list(Path(f"{folder}").glob("*.png"))) == 1
def test_categoryplot():
    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(
        df_dict_fruits["get_interest_over_time"],
        palette="dark",
        x_label="apple",
        y_label="pineapple",
    )
    data.builder = builder
    data.categoryplot()
    folder = f"{test_categoryplot.__name__}"
    builder.figure.save_all_figures(folder=folder)
    assert len(list(Path(f"{folder}").glob("*.png"))) == 1
def test_distributionplot():
    # Test distributionplot with new data set:
    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(
        df_dict_fruits["get_related_queries"]["apple"]["top"],
        palette="dark",
        x_label="value",
    )
    data.builder = builder
    data.distributionplot(kind="ecdf")
    folder = f"{test_distributionplot.__name__}"
    builder.figure.save_all_figures(folder=folder)
    assert len(list(Path(f"{folder}").glob("*.png"))) == 1
def test_pointplot():
    # Test pointplot with new data set:
    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(
        df_dict_fruits["get_interest_over_time"],
        x_label="apple",
        y_label="pineapple",
    )
    data.builder = builder
    data.pointplot()
    folder = f"{test_pointplot.__name__}"
    builder.figure.save_all_figures(folder=folder)
    assert len(list(Path(f"{folder}").glob("*.png"))) == 1
def test_boxenplot():
    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(
        df_dict_fruits["get_interest_over_time"],
        palette=sns.light_palette("purple"),
        dark_mode=True,
        grid=True,
    )
    data.builder = builder
    data.boxplot(multiboxen=True)
    folder = f"{test_boxenplot.__name__}"
    builder.figure.save_all_figures(folder=folder)
    assert len(list(Path(f"{folder}").glob("*.png"))) == 1
def test_scatterplot():
    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(
        df_dict_fruits["get_interest_over_time"],
        x_label="apple",
        y_label="pineapple",
        hue="super market",
        palette="ch:r=-.2,d=.3_r",
    )
    data.builder = builder
    data.scatterplot(size="home delivery")
    folder = f"{test_scatterplot.__name__}"
    builder.figure.save_all_figures(folder=folder)
    assert len(list(Path(f"{folder}").glob("*.png"))) == 1
def test_clustermap():
    df = sns.load_dataset("brain_networks", header=[0, 1, 2], index_col=0)

    # Select a subset of the networks
    used_networks = [1, 5, 6, 7, 8, 12, 13, 17]
    used_columns = (
        df.columns.get_level_values("network").astype(int).isin(used_networks))
    df = df.loc[:, used_columns]

    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(df)
    data.builder = builder
    data.clustermap()
    folder = f"{test_clustermap.__name__}"
    builder.figure.save_all_figures(folder=folder)
    assert len(list(Path(f"{folder}").glob("*.png"))) == 1
def test_swarmplot():
    data = dav.DataVisualization()
    builder = dav.DesignerDataVisualization(
        df_dict_fruits["get_interest_over_time"],
        palette="Set2",
    )
    data.builder = builder
    data.swarmplot(
        size=2,
        marker="D",
        edgecolor="gray",
        alpha=0.25,
    )
    folder = f"{test_swarmplot.__name__}"
    builder.figure.save_all_figures(folder=folder)
    assert len(list(Path(f"{folder}").glob("*.png"))) == 1