# Path: cogspaces/datasets/derivative.py
# def get_study_info():
#     input_data, targets = load_reduced_loadings(data_dir=get_data_dir())
#     targets = pd.concat(targets.values(), axis=0)
#     targets['#subjects'] = targets.groupby(by=['study', 'task', 'contrast'])['subject'].transform('nunique')
#     targets['#contrasts_per_task'] = targets.groupby(by=['study', 'task'])['contrast'].transform('nunique')
#     targets['#contrasts_per_study'] = targets.groupby(by='study')['contrast'].transform('nunique')
#     targets['chance_study'] = 1 / targets['#contrasts_per_study']
#     targets['chance_task'] = 1 / targets['#contrasts_per_task']
#     citations = _get_citations()
#     targets = pd.merge(targets, citations, on='study', how='left')
#     targets = targets.groupby(by=['study', 'task', 'contrast']).first().sort_index().drop(columns='index').reset_index()
# 
#     targets['study__task'] = targets.apply(lambda x: f'{x["study"]}__{x["task"]}', axis='columns')
#     targets['name_task'] = targets.apply(lambda x: f'[{x["bibkey"]}] {x["task"]}', axis='columns')
# 
#     def apply(x):
#         comment = x['comment'].iloc[0]
#         if comment != '':
#             tasks = comment
#             tasks_lim = comment
#         else:
#             tasks_list = x['task'].unique()
#             tasks = ' & '.join(tasks_list)
#             if len(tasks) > 50:
#                 tasks_lim = tasks_list[0] + ' & ...'
#             else:
#                 tasks_lim = tasks
#         name = f'[{x["bibkey"].iloc[0]}] {tasks_lim}'
#         latex_name = f'\cite{{{x["citekey"].iloc[0]}}} {tasks}'.replace('&', '\&')
#         name = pd.DataFrame(data={'name': name,
#                                   'latex_name':latex_name}, index=x.index)
#         return name
#     name = targets.groupby(by='study').apply(apply)
#     targets = pd.concat([targets, name], axis=1)
#     return targets
# 
# Path: cogspaces/datasets/utils.py
# def get_output_dir(output_dir=None):
#     """ Returns the directories in which to save output.
# 
#     Parameters
#     ----------
#     output_dir: string, optional
#         Path of the utils directory. Used to force utils storage in a specified
#         location. Default: None
# 
#     Returns
#     -------
#     path: string
#         Path of the output directory.
#     """
# 
#     # Check data_dir which force storage in a specific location
#     if output_dir is not None:
#         assert (isinstance(output_dir, str))
#         return output_dir
#     elif 'COGSPACES_OUTPUT' in os.environ:
#         return os.environ['COGSPACES_OUTPUT']
#     else:
#         return os.path.expanduser('~/cogspaces_data')


import os
import re
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
                import json
from os.path import join
from matplotlib import gridspec, ticker
from cogspaces.datasets.derivative import get_study_info
from cogspaces.datasets.utils import get_output_dir
    ax1 = fig.add_subplot(gs[0, 1], sharey=ax2)
    n_study = len(data)

    ind = np.arange(n_study) * 2 + .5
    width = 1.2
    diff_color = sns.color_palette("husl", n_study)[::-1]
    diff_color_err = [(max(0, r - .1), max(0, g - .1), max(0, b - .1))
                      for r, g, b in diff_color]

    baseline_color = '0.75'
    baseline_color_err = '0.65'
    transfer_color = '0.1'
    transfer_color_err = '0.'
    ax1.barh(ind, data[('diff_with_baseline', 'mean')], width,
             color=diff_color)
    for this_x, this_y, this_xerr, this_color in zip(
            data[('diff_with_baseline', 'mean')],
            ind,
            data[('diff_with_baseline', 'std')],
            diff_color_err):
        ax1.errorbar(this_x, this_y, xerr=this_xerr, elinewidth=1.5,
                     capsize=2, linewidth=0, ecolor=this_color,
                     alpha=.5)
    ax1.set_xlabel('Multi-study acc. gain' if not split_by_task else 'Multi-task acc. gain', fontsize=12)
    ax1.spines['left'].set_position('zero')
    plt.setp(ax1.get_yticklabels(), visible=False)

    # ax1.set_xlim([-0.06, 0.19])
    ax1.xaxis.set_major_locator(ticker.MultipleLocator(0.1))
    ax1.xaxis.set_minor_locator(ticker.MultipleLocator(0.025))

# Path: cogspaces/datasets/derivative.py
# def get_study_info():
#     input_data, targets = load_reduced_loadings(data_dir=get_data_dir())
#     targets = pd.concat(targets.values(), axis=0)
#     targets['#subjects'] = targets.groupby(by=['study', 'task', 'contrast'])['subject'].transform('nunique')
#     targets['#contrasts_per_task'] = targets.groupby(by=['study', 'task'])['contrast'].transform('nunique')
#     targets['#contrasts_per_study'] = targets.groupby(by='study')['contrast'].transform('nunique')
#     targets['chance_study'] = 1 / targets['#contrasts_per_study']
#     targets['chance_task'] = 1 / targets['#contrasts_per_task']
#     citations = _get_citations()
#     targets = pd.merge(targets, citations, on='study', how='left')
#     targets = targets.groupby(by=['study', 'task', 'contrast']).first().sort_index().drop(columns='index').reset_index()
# 
#     targets['study__task'] = targets.apply(lambda x: f'{x["study"]}__{x["task"]}', axis='columns')
#     targets['name_task'] = targets.apply(lambda x: f'[{x["bibkey"]}] {x["task"]}', axis='columns')
# 
#     def apply(x):
#         comment = x['comment'].iloc[0]
#         if comment != '':
#             tasks = comment
#             tasks_lim = comment
#         else:
#             tasks_list = x['task'].unique()
#             tasks = ' & '.join(tasks_list)
#             if len(tasks) > 50:
#                 tasks_lim = tasks_list[0] + ' & ...'
#             else:
#                 tasks_lim = tasks
#         name = f'[{x["bibkey"].iloc[0]}] {tasks_lim}'
#         latex_name = f'\cite{{{x["citekey"].iloc[0]}}} {tasks}'.replace('&', '\&')
#         name = pd.DataFrame(data={'name': name,
#                                   'latex_name':latex_name}, index=x.index)
#         return name
#     name = targets.groupby(by='study').apply(apply)
#     targets = pd.concat([targets, name], axis=1)
#     return targets
# 
# Path: cogspaces/datasets/utils.py
# def get_output_dir(output_dir=None):
#     """ Returns the directories in which to save output.
# 
#     Parameters
#     ----------
#     output_dir: string, optional
#         Path of the utils directory. Used to force utils storage in a specified
#         location. Default: None
# 
#     Returns
#     -------
#     path: string
#         Path of the output directory.
#     """
# 
#     # Check data_dir which force storage in a specific location
#     if output_dir is not None:
#         assert (isinstance(output_dir, str))
#         return output_dir
#     elif 'COGSPACES_OUTPUT' in os.environ:
#         return os.environ['COGSPACES_OUTPUT']
#     else:
#         return os.path.expanduser('~/cogspaces_data')


# Path: exps/compare.py
import os
import re
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
                import json
from os.path import join
from matplotlib import gridspec, ticker
from cogspaces.datasets.derivative import get_study_info
from cogspaces.datasets.utils import get_output_dir

    ax1 = fig.add_subplot(gs[0, 1], sharey=ax2)
    n_study = len(data)

    ind = np.arange(n_study) * 2 + .5
    width = 1.2
    diff_color = sns.color_palette("husl", n_study)[::-1]
    diff_color_err = [(max(0, r - .1), max(0, g - .1), max(0, b - .1))
                      for r, g, b in diff_color]

    baseline_color = '0.75'
    baseline_color_err = '0.65'
    transfer_color = '0.1'
    transfer_color_err = '0.'
    ax1.barh(ind, data[('diff_with_baseline', 'mean')], width,
             color=diff_color)
    for this_x, this_y, this_xerr, this_color in zip(
            data[('diff_with_baseline', 'mean')],
            ind,
            data[('diff_with_baseline', 'std')],
            diff_color_err):
        ax1.errorbar(this_x, this_y, xerr=this_xerr, elinewidth=1.5,
                     capsize=2, linewidth=0, ecolor=this_color,
                     alpha=.5)
    ax1.set_xlabel('Multi-study acc. gain' if not split_by_task else 'Multi-task acc. gain', fontsize=12)
    ax1.spines['left'].set_position('zero')
    plt.setp(ax1.get_yticklabels(), visible=False)

    # ax1.set_xlim([-0.06, 0.19])
    ax1.xaxis.set_major_locator(ticker.MultipleLocator(0.1))
    ax1.xaxis.set_minor_locator(ticker.MultipleLocator(0.025))

    ax1.xaxis.set_major_formatter(ticker.PercentFormatter(xmax=1, decimals=0))