Ejemplo n.º 1
0
    MILD_rehearsal_min='MILD rehearsal\nlength (minutes)',
    n_reality_checks='Number of\nreality checks',
    MILD_awake_min='MILD awake\nlength (minutes)',
)
XTICKS_MAJOR = dict(  # the spacing for MultipleLocator
    MILD_rehearsal_min=5,
    n_reality_checks=5,
    MILD_awake_min=20,
)
XTICKS_MINOR = dict(
    MILD_rehearsal_min=1,
    n_reality_checks=1,
    MILD_awake_min=5,
)

PALETTE = {x: myplt.dlqcolor(x) for x in myplt.DLQ_STRINGS.keys()}

FIG_HEIGHT = 2.5
FIG_WIDTH = 1.5 * len(PREDICTORS)

###################################

########  draw plot  ########

# load data
df = pd.read_csv(IMPORT_FNAME)

# drop all nights without recall
df.dropna(subset=['dream_report'], axis=0, inplace=True)

fig, axes = plt.subplots(1, len(PREDICTORS), figsize=(FIG_WIDTH, FIG_HEIGHT))
Ejemplo n.º 2
0
df = pd.read_csv(infname, sep='\t', index_col='MILD_rehearsal_min')

# run a cumulative sum across response options for plotting
# cumsum_cols = df.columns.sort_values(ascending=False).tolist()
assert all(df.columns.sort_values() == df.columns)
cumsum_df = df.cumsum(axis=1)

#########  draw plot  #########

xvals = cumsum_df.index.values

fig, ax = plt.subplots(figsize=(7, 6))

for col, series in cumsum_df.iteritems():
    color = myplt.dlqcolor(int(col[-1]))
    zorder = df.columns[::-1].tolist().index(col) - 10
    ax.fill_between(xvals, series.values, color=color, zorder=zorder)

ax.set_xlim(xvals.min(), xvals.max())
ax.set_ylim(0, 1)
ax.set_yticks([0, 1])
ax.xaxis.set_major_locator(MultipleLocator(20))
ax.xaxis.set_minor_locator(MultipleLocator(5))
ax.set_xlabel('MILD rehearsal length (minutes)')
ax.set_ylabel('Probability of reaching lucidity level')

ax.legend(handles=myplt.dlqpatches,
          loc='lower left',
          title='I was aware that I was dreaming.',
          frameon=False)
Ejemplo n.º 3
0
XTICKS_MAJOR = dict( # the spacing for MultipleLocator
    MILD_rehearsal_min=5,
    n_reality_checks=5,
    MILD_awake_min=20,
)
XTICKS_MINOR = dict(
    MILD_rehearsal_min=1,
    n_reality_checks=1,
    MILD_awake_min=5,
)

# # only keep rows with recall
# mildlength = df.loc[~df['DLQ:1'].isnull(),'mildlength'].values
# dlqresp    = df.loc[~df['DLQ:1'].isnull(),'DLQ:1'].values

palette = { x: myplt.dlqcolor(x) for x in myplt.DLQ_STRINGS.keys() }

fig, axes = plt.subplots(1,len(PREDICTORS),figsize=(5*len(PREDICTORS),6))

for i, (ax,col) in enumerate(zip(axes,PREDICTORS)):

    sea.swarmplot(y='DLQ_01',x=col,data=df,
        size=8,linewidth=1,#jitter=.2,
        palette=palette,
        ax=ax,orient='h')

    # aesthetics
    ax.set_ylim(-.7,4.7)
    ax.set_yticks([0,1,2,3,4])
    ax.xaxis.set_major_locator(MultipleLocator(XTICKS_MAJOR[col]))
    ax.xaxis.set_minor_locator(MultipleLocator(XTICKS_MINOR[col]))
Ejemplo n.º 4
0
    xvals = np.arange(4).astype(float)
    if ev == 'ld_per_night':
        xvals -= .07
    elif ev == 'ld_per_dream':
        xvals += .07
    yvals = subdf['mean']

    if ev != 'binary_ld':
        yerr  = subdf['sem']
        ax.errorbar(xvals,yvals,yerr,
            color='k',linestyle='-',linewidth=.5,zorder=1)
    else:
        ax.plot(xvals,yvals,
            color='k',linestyle='-',linewidth=.5,zorder=1)
    ax.scatter(xvals,yvals,
        color=[ myplt.dlqcolor(i) for i in range(1,5) ],
        marker=MARKERS[ev],edgecolors='w',
        s=70,zorder=2,linewidths=1)

# handle the xaxis
ax.set_xticks(range(4))
xticklabels = [ myplt.DLQ_STRINGS[i] for i in range(1,5) ]
xticklabels = [ x if x == 'Very much' else f'>= {x}'
                for x in xticklabels ]
ax.set_xticklabels(xticklabels,rotation=25,ha='right')
ax.set_xlabel('Lucidity cutoff')

# handle yaxes
ax.yaxis.set_major_locator(mticker.MultipleLocator(.5))
ax.yaxis.set_minor_locator(mticker.MultipleLocator(.1))
ax.set_xlim(-0.5,3.5)
Ejemplo n.º 5
0
# # since we also highlight how it depends on how
# # you measure success. But run this just to be able
# # to say there were about half LDs
# obs = [nonlucid,nonzero_lucid]
# p = stats.binom_test(obs,p=0.5,alternative='two-sided')
# stats_df.loc['zeroVSnonzero_DLQ01',['test','chisq','pval']] = ['binomial',np.nan,p]


# ####################################


##########  draw all frequencies  ###########

fig, ax = plt.subplots(figsize=(FIG_WIDTH,FIG_HEIGHT))

colors = [ myplt.dlqcolor(i) for i in range(5) ]
xvals = range(5)
ax.bar(xvals,freqs,color=colors,edgecolor='k',width=1,linewidth=.5)

ax.set_xlim(-.75,4.75)
ax.set_ylim(0,max(freqs)+1)
ax.yaxis.set_major_locator(mticker.MultipleLocator(20))
ax.yaxis.set_minor_locator(mticker.MultipleLocator(5))
ax.set_xticks(range(5))
ax.set_xticklabels(list(myplt.DLQ_STRINGS.values()),rotation=25,
                   ha='right',fontsize=TICK_FONTSIZE)
ax.set_ylabel('Number of nights')
ax.set_xlabel('Lucidity')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
Ejemplo n.º 6
0
# run a cumulative sum across response options for plotting
cumsum_cols = np.roll(df.columns.sort_values(ascending=False), -1).tolist()
cumsum_df = df[cumsum_cols].cumsum(axis=1)

# save
cumsum_df.to_csv(EXPORT_FNAME_DATA, index=True)

#############################################

#########  draw the plot  #########

fig, ax = plt.subplots(figsize=(FIG_WIDTH, FIG_HEIGHT))

xvals = range(cumsum_df.index.size)
for col, series in cumsum_df.iteritems():
    color = myplt.NORECALL_COLOR if col == 'No recall' else myplt.dlqcolor(
        int(col[-1]))
    zorder = cumsum_cols[::-1].index(col)
    ax.barh(y=xvals,
            width=series.values,
            zorder=zorder,
            color=color,
            edgecolor='k',
            linewidth=0)
    if col == 'DLQ01_resp-0':
        ax.barh(y=xvals,
                width=series.values,
                zorder=10,
                color='none',
                edgecolor='k',
                linewidth=1)