Add an option to print figures and set font sizes.

communication
junos 2021-08-04 17:41:09 +02:00
parent 1bdb334c42
commit 9e87b1f176
2 changed files with 43 additions and 22 deletions

View File

@ -6,7 +6,7 @@
# extension: .py # extension: .py
# format_name: percent # format_name: percent
# format_version: '1.3' # format_version: '1.3'
# jupytext_version: 1.11.2 # jupytext_version: 1.11.4
# kernelspec: # kernelspec:
# display_name: straw2analysis # display_name: straw2analysis
# language: python # language: python
@ -14,6 +14,7 @@
# --- # ---
# %% # %%
# %matplotlib inline
import os import os
import sys import sys

View File

@ -6,7 +6,7 @@
# extension: .py # extension: .py
# format_name: percent # format_name: percent
# format_version: '1.3' # format_version: '1.3'
# jupytext_version: 1.11.2 # jupytext_version: 1.11.4
# kernelspec: # kernelspec:
# display_name: straw2analysis # display_name: straw2analysis
# language: python # language: python
@ -14,12 +14,12 @@
# --- # ---
# %% # %%
# %matplotlib inline
import datetime import datetime
# %%
import os import os
import sys import sys
import matplotlib.pyplot as plt
import pandas as pd import pandas as pd
import seaborn as sns import seaborn as sns
import statsmodels.api as sm import statsmodels.api as sm
@ -31,6 +31,24 @@ if nb_dir not in sys.path:
import participants.query_db import participants.query_db
from features.esm import * from features.esm import *
# %%
SAVE_FIGS = True
FIG_HEIGHT = 5
FIG_ASPECT = 1.6
FIG_COLOUR = "#28827C"
SMALL_SIZE = 10
MEDIUM_SIZE = 12
BIGGER_SIZE = 14
plt.rc("font", size=SMALL_SIZE) # controls default text sizes
plt.rc("axes", titlesize=SMALL_SIZE) # fontsize of the axes title
plt.rc("axes", labelsize=MEDIUM_SIZE) # fontsize of the x and y labels
plt.rc("xtick", labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc("ytick", labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc("legend", fontsize=SMALL_SIZE) # legend fontsize
plt.rc("figure", titlesize=BIGGER_SIZE) # fontsize of the figure title
# %% # %%
baseline_si = pd.read_csv("E:/STRAWbaseline/results-survey637813.csv") baseline_si = pd.read_csv("E:/STRAWbaseline/results-survey637813.csv")
baseline_be_1 = pd.read_csv("E:/STRAWbaseline/results-survey358134.csv") baseline_be_1 = pd.read_csv("E:/STRAWbaseline/results-survey358134.csv")
@ -130,7 +148,7 @@ df_adherence.describe()
df_adherence[["gender", "startlanguage"]].value_counts() df_adherence[["gender", "startlanguage"]].value_counts()
# %% # %%
sns.displot(df_adherence["finished_sessions"], binwidth=5, height=5) sns.displot(df_adherence["finished_sessions"], binwidth=5, height=FIG_HEIGHT)
# %% # %%
lm_adherence = smf.ols( lm_adherence = smf.ols(
@ -224,12 +242,14 @@ df_session_workday = df_session_workday.assign(
g1 = sns.displot( g1 = sns.displot(
df_session_workday["time_diff_minutes"], df_session_workday["time_diff_minutes"],
binwidth=5, binwidth=5,
height=5, height=FIG_HEIGHT,
aspect=1.5, aspect=FIG_ASPECT,
color="#28827C", color=FIG_COLOUR,
) )
g1.set_axis_labels("Time difference [min]", "Session count") g1.set_axis_labels("Time difference [min]", "Session count")
# g1.savefig("WorkdayEMAtimeDiff.pdf") g1.set(xlim=(0, 570))
if SAVE_FIGS:
g1.savefig("WorkdayEMAtimeDiff.pdf")
# %% [markdown] # %% [markdown]
# There are some sessions that are really close together. By design, none should be closer than 30 min. Let's take a look at those. # There are some sessions that are really close together. By design, none should be closer than 30 min. Let's take a look at those.
@ -296,12 +316,13 @@ df_mean_daytime_interval.describe()
g2 = sns.displot( g2 = sns.displot(
df_mean_daytime_interval.time_diff_minutes, df_mean_daytime_interval.time_diff_minutes,
binwidth=5, binwidth=5,
height=5, height=FIG_HEIGHT,
aspect=1.5, aspect=FIG_ASPECT,
color="#28827C", color=FIG_COLOUR,
) )
g2.set_axis_labels("Median time difference [min]", "Participant count") g2.set_axis_labels("Median time difference [min]", "Participant count")
# g2.savefig("WorkdayEMAtimeDiffMedianParticip.pdf") if SAVE_FIGS:
g2.savefig("WorkdayEMAtimeDiffMedianParticip.pdf")
# %% # %%
df_adherence = df_adherence.merge( df_adherence = df_adherence.merge(
@ -327,9 +348,9 @@ df_count_daytime_per_participant["time"].describe()
sns.displot( sns.displot(
df_count_daytime_per_participant.time, df_count_daytime_per_participant.time,
binwidth=1, binwidth=1,
height=5, height=FIG_HEIGHT,
aspect=1.5, aspect=FIG_ASPECT,
color="#28827C", color=FIG_COLOUR,
) )
# %% [markdown] # %% [markdown]
@ -364,13 +385,14 @@ s_evening_completed_ratio.describe()
g3 = sns.displot( g3 = sns.displot(
s_evening_completed_ratio - 0.001, s_evening_completed_ratio - 0.001,
binwidth=0.05, binwidth=0.05,
height=5, height=FIG_HEIGHT,
aspect=1.5, aspect=FIG_ASPECT,
color="#28827C", color=FIG_COLOUR,
) )
g3.set_axis_labels("Ratio of days with the evening EMA filled out", "Participant count") g3.set_axis_labels("Ratio of days with the evening EMA filled out", "Participant count")
g3.set(xlim=(1.01, 0.59)) g3.set(xlim=(1.01, 0.59))
# g3.savefig("EveningEMAratioParticip.pdf") if SAVE_FIGS:
g3.savefig("EveningEMAratioParticip.pdf")
# %% # %%
df_adherence = df_adherence.merge( df_adherence = df_adherence.merge(
@ -386,5 +408,3 @@ lr_ols_evening_ratio = smf.ols(
) )
ls_result_evening_ratio = lr_ols_evening_ratio.fit() ls_result_evening_ratio = lr_ols_evening_ratio.fit()
ls_result_evening_ratio.summary() ls_result_evening_ratio.summary()
# %%