<jupyter_start><jupyter_text>Plot the task canoncial vecotrs<jupyter_code># change verbal fluency to category fluency and reverse the sign for presentation
print(task_labels)
task_labels[1] = 'Category Fluency'
sig_mod['v'][1, :]  = sig_mod['v'][1, :] * -1 

f, ax = plt.subplots(1, figsize=(10, 10))
df_v = pd.DataFrame(sig_mod['v'], 
                    index=task_labels, 
                    columns=['1', '2'])
sns.heatmap(df_v,
            center=0,
            square=True, annot=True,
            cbar_kws={'label': 'Canonical vectors'},
            cmap='cold_hot')

f.tight_layout()
f.savefig('./reports/figures/S1-cognitive_task_heatmap.png', dpi=300, transparent=True)
df_v['1'].to_csv(f"reports/manuscript/mode_1_task.txt", sep='\t')
df_v['2'].to_csv(f"reports/manuscript/mode_2_task.txt", sep='\t')<jupyter_output>['Digit Span', 'Category Fluency', 'Picture Naming', 'TS-Flexibility', 'TS-Inhibition', 'Four Mountains', 'Unusual Uses', 'RAPM', 'Paired Associate', 'Semantics - Strength', 'Semantics - Modality', 'Semantics - Specificity', 'Semantics - Feature Matching']<jupyter_text>word cloud color generation<jupyter_code>import matplotlib.colors as mcolor
import matplotlib.colorbar as mcb
import matplotlib.cm as mcm

# load the principle vector and mind-wandering labels
df_pc = pd.DataFrame(sig_mod['v'], 
                     index=task_labels,
                     columns=['1', '2'])

pv_in_hex= []
vmax = np.abs(df_pc.values).max()
vmin = -vmax
for i in range(df_pc.values.shape[1]):
    rescale = (df_pc.values[:,i] - vmin) / (vmax - vmin)
    colors_hex = []
    for c in mcm.RdBu_r(rescale):
        colors_hex.append(mcolor.to_hex(c))
    pv_in_hex.append(colors_hex)
colors_hex = np.array(pv_in_hex).T
df_v_color = pd.DataFrame(colors_hex, columns=df_pc.columns, index=df_pc.index)
print(vmax)
print(vmin)
set_text_size(10)

fig = plt.figure(figsize=(3, 0.8))
ax = fig.add_subplot(111)
cmap = mcm.RdBu_r
norm = mcolor.Normalize(vmin=vmin, vmax=vmax)
cb1 = mcb.ColorbarBase(ax, cmap=cmap,
                                norm=norm, orientation='horizontal')
plt.tight_layout()
# plt.savefig('reports/figures/task_canonicalweights_wordcloud_cb.png', transparent=True, dpi=300)
for n in range(2):
    i = str(n + 1)
    df = pd.concat([df_pc[i], df_v_color[i]], axis=1)
    df.reset_index(level=0, inplace=True)
    df.columns = ['word', 'ori_weight', 'color']
    df['weight'] = np.round(np.abs(df['ori_weight'] * 100))
    df = df[['weight', 'word', 'color']]
    df.to_csv('reports/figures/CCA/task_canonicalweights_wordcloud_colors_{}.csv'.format(i))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15970892378399082, 'fraction_numerical': 0.0160857908847185, 'mean_word_length': 4.141732283464567, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '129575', 'license': 'MIT', 'n_tokens_mistral': 1033, 'n_tokens_neox': 978, 'n_words': 173, 'path': 'notebooks/S1-CognitiveTasks_heatmap.ipynb', 'repo_name': 'htwangtw/Wang2020_taskSCCA', 'size': '2611'}