-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#56 complete restructure of stage plots
- Loading branch information
1 parent
3ecc914
commit 72e5b82
Showing
8 changed files
with
865 additions
and
87 deletions.
There are no files selected for viewing
596 changes: 588 additions & 8 deletions
596
notebooks/dj_exploratory_notebooks/fixationgrower_initial_plots.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import seaborn as sns | ||
import pandas as pd | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
from behav_viz.utils import plot_utils as pu | ||
import behav_viz.visualize as viz | ||
|
||
###################### STAGE ###################### | ||
|
||
|
||
def plot_ma_stage( | ||
df, | ||
ax=None, | ||
x_var="date", | ||
title="", | ||
ylim=None, | ||
rotate_x_labels=False, | ||
relative_to_stage=None, | ||
**kwargs | ||
): | ||
|
||
if ax is None: | ||
fig, ax = pu.make_fig() | ||
|
||
# plot each animal as a gray line | ||
for _, sub_df in df.groupby("animal_id"): | ||
viz.plots.plot_stage( | ||
sub_df, | ||
x_var=x_var, | ||
ax=ax, | ||
alpha=0.5, | ||
color="gray", | ||
relative_to_stage=relative_to_stage, | ||
) | ||
|
||
# plot the mean of the animals | ||
viz.plots.plot_stage( | ||
df, | ||
x_var=x_var, | ||
ax=ax, | ||
rotate_x_labels=rotate_x_labels, | ||
ylim=ylim, | ||
relative_to_stage=relative_to_stage, | ||
**kwargs | ||
) | ||
|
||
|
||
def plot_ma_stage_by_condition( | ||
df, | ||
condition, | ||
ax=None, | ||
x_var="date", | ||
title="", | ||
palette="husl", | ||
ylim=None, | ||
rotate_x_labels=False, | ||
relative_to_stage=None, | ||
**kwargs | ||
): | ||
|
||
if ax is None: | ||
fig, ax = pu.make_fig() | ||
|
||
# hacky way of plot multi animals with respective colors | ||
pal = sns.color_palette(palette, len(df[condition].unique())) | ||
for ii, (cond, sub_df) in enumerate(df.groupby([condition])): | ||
|
||
color = pal[ii] | ||
|
||
for _, sub_sub_df in sub_df.groupby("animal_id"): | ||
viz.plots.plot_stage( | ||
sub_sub_df, | ||
x_var=x_var, | ||
ax=ax, | ||
alpha=0.5, | ||
color=color, | ||
relative_to_stage=relative_to_stage, | ||
**kwargs | ||
) | ||
|
||
# plot the mean of the animals | ||
viz.plots.plot_stage( | ||
df, | ||
hue=condition, | ||
x_var=x_var, | ||
ax=ax, | ||
rotate_x_labels=rotate_x_labels, | ||
ylim=ylim, | ||
palette=pal, | ||
relative_to_stage=relative_to_stage, | ||
**kwargs | ||
) | ||
|
||
_ = ax.set( | ||
ylabel="Stage", | ||
title=title, | ||
) | ||
|
||
return None | ||
|
||
|
||
def plot_ma_days_in_stage( | ||
df, ax=None, min_stage=None, max_stage=None, plot_individuals=True, **kwargs | ||
): | ||
|
||
if ax is None: | ||
fig, ax = pu.make_fig((6, 4)) | ||
|
||
days_in_stage_df = viz.df_preperation.make_days_in_stage_df( | ||
df, min_stage, max_stage | ||
) | ||
|
||
sns.boxplot( | ||
data=days_in_stage_df, | ||
x="stage", | ||
y="n_days", | ||
color="white", | ||
**kwargs, | ||
ax=ax, | ||
showfliers=False | ||
) | ||
if plot_individuals: | ||
sns.swarmplot( | ||
data=days_in_stage_df, x="stage", y="n_days", label="", color="gray", ax=ax | ||
) | ||
|
||
_ = ax.set(ylabel="N Days", xlabel="Stage") | ||
sns.despine() | ||
|
||
return None |
Oops, something went wrong.