diff --git a/pyproject.toml b/pyproject.toml index 5b2826a..a4a4713 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ dependencies = [ "numpy", "pandas", "seaborn", - "statannot", + "statannotations", "scipy" ] diff --git a/swarm_visualizer/lineplot.py b/swarm_visualizer/lineplot.py index 7d8e0a2..2159fe4 100644 --- a/swarm_visualizer/lineplot.py +++ b/swarm_visualizer/lineplot.py @@ -5,18 +5,18 @@ from swarm_visualizer.utility.general_utils import set_axis_infos -def plot_basic_plot_ts( - ts_vector=None, +def plot_basic_lineplot( + vector=None, title_str: str = None, ylabel: str = None, lw: float = 3.0, ylim=None, - xlabel: str = "time", + xlabel: str = "x", ax=None, ) -> None: - """Basic plot of a time series. + """Basic lineplot. - :param ts_vector: time series + :param vector: vector to plot :param title_str: title of the plot :param ylabel: y-axis label :param lw: line width @@ -26,18 +26,18 @@ def plot_basic_plot_ts( :return: None. """ # Plot time series - ax.plot(ts_vector, lw=lw) + ax.plot(vector, lw=lw) set_axis_infos( ax, xlabel=xlabel, ylabel=ylabel, ylim=ylim, title_str=title_str ) -def plot_overlaid_ts( +def plot_overlaid_lineplot( normalized_ts_dict: Dict = None, title_str: str = None, ylabel: str = None, - xlabel: str = "time", + xlabel: str = "x", xticks=None, ylim=None, DEFAULT_ALPHA: float = 1.0, @@ -46,9 +46,9 @@ def plot_overlaid_ts( delete_yticks: bool = False, ax=None, ) -> None: - """Overlaid time series plot. + """Overlaid line plot. - :param normalized_ts_dict: dictionary with time series to plot + :param normalized_ts_dict: dictionary with values to plot :param title_str: title of the plot :param ylabel: y-axis label :param xlabel: x-axis label diff --git a/swarm_visualizer/utility/statistics_utils.py b/swarm_visualizer/utility/statistics_utils.py index 2378d5c..09c4b74 100644 --- a/swarm_visualizer/utility/statistics_utils.py +++ b/swarm_visualizer/utility/statistics_utils.py @@ -1,4 +1,5 @@ -from statannot import add_stat_annotation +from statannotations.Annotator import Annotator + def add_wilcoxon_value( @@ -15,17 +16,7 @@ def add_wilcoxon_value( fontsize=20, verbose=0, ) -> None: - add_stat_annotation( - ax, - data=df, - x=x_var, - y=y_var, - hue=hue, - order=order_list, - box_pairs=box_pairs, - test=test_type, - text_format=text_format, - loc=loc, - verbose=verbose, - fontsize=fontsize, - ) + + annotator = Annotator(ax,box_pairs,data=df, x=x_var, y=y_var, hue = hue, order=order_list) + annotator.configure(test=test_type, text_format=text_format, loc=loc, verbose=verbose, fontsize=fontsize) + annotator.apply_and_annotate() diff --git a/tests/test_lineplot.py b/tests/test_lineplot.py index ec49be9..d5c007f 100644 --- a/tests/test_lineplot.py +++ b/tests/test_lineplot.py @@ -6,7 +6,7 @@ import numpy as np import pytest -from swarm_visualizer.lineplot import plot_basic_plot_ts, plot_overlaid_ts +from swarm_visualizer.lineplot import plot_basic_lineplot, plot_overlaid_lineplot from swarm_visualizer.utility.general_utils import save_fig, set_plot_properties _X_DATA = np.arange(0, 10, 0.1) + np.random.normal(0, 0.1, 100) @@ -56,7 +56,7 @@ @pytest.mark.parametrize(("ts_vector"), ([_X_DATA])) -def test_basic_ts_plot(ts_vector) -> None: +def test_basic_lineplot(ts_vector) -> None: """Tests basic time series plot. :param ts_vector: time series @@ -68,9 +68,9 @@ def test_basic_ts_plot(ts_vector) -> None: fig, ax = plt.subplots(figsize=(10, 10)) # Plot time series - plot_basic_plot_ts( - ts_vector=ts_vector, - title_str="Basic Time Series Plot", + plot_basic_lineplot( + vector=ts_vector, + title_str="Basic Line Plot", ylabel="$y$", lw=3.0, ylim=None, @@ -84,7 +84,7 @@ def test_basic_ts_plot(ts_vector) -> None: @pytest.mark.parametrize(("normalized_ts_dict"), ([_NORMALIZED_TS_DICT])) -def test_overlaid_ts_plot(normalized_ts_dict) -> None: +def test_overlaid_lineplot(normalized_ts_dict) -> None: """Tests overlaid time series plot. :param normalized_ts_dict: dictionary with time series to plot @@ -96,9 +96,9 @@ def test_overlaid_ts_plot(normalized_ts_dict) -> None: fig, ax = plt.subplots(figsize=(10, 10)) # Plot overlaid time series - plot_overlaid_ts( + plot_overlaid_lineplot( normalized_ts_dict=normalized_ts_dict, - title_str="Overlaid Time Series Plot", + title_str="Overlaid Line Plot", ylabel="$y$", xlabel="$x$", xticks=None, diff --git a/tests/test_p_value.py b/tests/test_p_value.py index f67661e..d1d9801 100644 --- a/tests/test_p_value.py +++ b/tests/test_p_value.py @@ -30,7 +30,7 @@ ) _DATA_FRAME = pd.DataFrame( - {"$y$": _X_DATA, "$x$": _X_LABEL, "_GROUPS": _GROUPS} + {"$y$": _X_DATA, "$x$": _X_LABEL, "hue": _GROUPS} ) _SAVE_LOC = os.path.abspath( os.path.join(os.path.dirname(__file__), "example_plots") @@ -38,7 +38,7 @@ @pytest.mark.parametrize( - ("df", "x_var", "y_var", "hue"), [(_DATA_FRAME, "$x$", "$y$", _GROUPS)] + ("df", "x_var", "y_var", "hue"), [(_DATA_FRAME, "$x$", "$y$", "hue")] ) def test_star_pvalue(df, x_var, y_var, hue) -> None: """Tests paired boxplot.