Skip to content

Commit

Permalink
Merge pull request #21 from UTAustin-SwarmLab/lineplot_and_p_value_fixes
Browse files Browse the repository at this point in the history
Fixed P value plots and line plots naming
  • Loading branch information
d31003 authored Mar 20, 2024
2 parents e412160 + 0474cfb commit e23e075
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 36 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies = [
"numpy",
"pandas",
"seaborn",
"statannot",
"statannotations",
"scipy"
]

Expand Down
20 changes: 10 additions & 10 deletions swarm_visualizer/lineplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down
21 changes: 6 additions & 15 deletions swarm_visualizer/utility/statistics_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from statannot import add_stat_annotation
from statannotations.Annotator import Annotator



def add_wilcoxon_value(
Expand All @@ -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()
16 changes: 8 additions & 8 deletions tests/test_lineplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_p_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
)

_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")
)


@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.
Expand Down

0 comments on commit e23e075

Please sign in to comment.