In [1]:
import matplotlib.pyplot as plt
%matplotlib inline

import seaborn as sns
sns.set_context('talk')

from matplotlib.ticker import FuncFormatter

In [2]:
labelsize = 15

In [3]:
def scientific_tex_formatter(x, pos):
    if x == 0.:
        return r'$0$'
    
    str_ = "%.1e" % x
    
    #str_ = str_.replace('1.0', '')
    str_ = str_.replace('e-0', '\,\,10^{-')
    str_ = str_.replace('e+0', '\,\,10^{')
    
    str_ = str_ + '}'
    str_ = r'$%s$' % str_
    
    return str_

f_scientific_tex_formatter = FuncFormatter(scientific_tex_formatter)

def scientific_tex_formatter2(x, pos):
    if x == 1.:
        return r'$1$'
    
    str_ = "%.1e" % x
    
    str_ = str_.replace('1.0', '')
    str_ = str_.replace('e-0', '\,\,10^{-')
    str_ = str_.replace('e+0', '\,\,10^{')
    
    str_ = str_ + '}'
    str_ = r'$%s$' % str_
    
    return str_

f_scientific_tex_formatter2 = FuncFormatter(scientific_tex_formatter2)

In [4]:
def tex_foramtter(x, pos):
    return r'$\rm{%s}$' % x

f_tex_foramtter = FuncFormatter(tex_foramtter)

def tex_transf(x):
    return r'$\rm{%s}$' % x

In [5]:
def tex_pct_formatter(x, pos):
    return r'$%.0f \%%$' % x

f_tex_pct_formatter = FuncFormatter(tex_pct_formatter)

In [6]:
import pandas as pd
import numpy as np

import os

In [7]:
dir_res_ = './results'

In [8]:
im_2 = pd.read_csv(os.path.join(dir_res_, 'IM_nu_eq_2.csv'), header=0, index_col=0)
im_6 = pd.read_csv(os.path.join(dir_res_, 'IM_nu_eq_6.csv'), header=0, index_col=0)
im_50 = pd.read_csv(os.path.join(dir_res_, 'IM_nu_eq_50.csv'), header=0, index_col=0)

Monetary Allocation

IM 99 %


In [9]:
im_99pct = pd.DataFrame()

im_99pct[r'$\nu = 2$'] = im_2['99.0']
im_99pct[r'$\nu = 6$'] = im_6['99.0']
im_99pct[r'$\nu = 50$'] = im_50['99.0']

In [10]:
f, ax = plt.subplots()

im_99pct.sort_values(r'$\nu = 2$')[::-1].plot.bar(ax=ax)

labels = ['' for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

ax.yaxis.set_major_formatter(f_scientific_tex_formatter)

plt.tick_params(axis='both', which='major', labelsize=labelsize)
plt.legend(fontsize=labelsize)

plt.show()



In [11]:
f, ax = plt.subplots()

im_99pct.sort_values(r'$\nu = 2$')[::-1][:10].plot.bar(ax=ax)

labels = [tex_transf(item.get_text()) for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

for label in ax.get_xticklabels():
    label.set_rotation(0) 

ax.yaxis.set_major_formatter(f_scientific_tex_formatter)

plt.tick_params(axis='both', which='major', labelsize=labelsize)
plt.legend(fontsize=labelsize)

plt.show()


IM 99.7 %


In [12]:
im_997pct = pd.DataFrame()

im_997pct[r'$\nu = 2$'] = im_2['99.7']
im_997pct[r'$\nu = 6$'] = im_6['99.7']
im_997pct[r'$\nu = 50$'] = im_50['99.7']

In [13]:
f, ax = plt.subplots()

im_997pct.sort_values(r'$\nu = 2$')[::-1].plot.bar(ax=ax)

labels = ['' for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

ax.yaxis.set_major_formatter(f_scientific_tex_formatter)

plt.tick_params(axis='both', which='major', labelsize=labelsize)
plt.legend(fontsize=labelsize)

plt.show()



In [14]:
f, ax = plt.subplots()

im_997pct.sort_values(r'$\nu = 2$')[::-1][:10].plot.bar(ax=ax)

labels = [tex_transf(item.get_text()) for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

for label in ax.get_xticklabels():
    label.set_rotation(0) 

ax.yaxis.set_major_formatter(f_scientific_tex_formatter)

plt.tick_params(axis='both', which='major', labelsize=labelsize)
plt.legend(fontsize=labelsize)

plt.show()


Weights Allocation

IM 99 %


In [15]:
im_99pct_weights = im_99pct

for col in im_99pct_weights.columns:
    im_99pct_weights[col] = im_99pct_weights[col] / im_99pct_weights[col].sum() * 100.

im_99pct_weights.head()


Out[15]:
$\nu = 2$ $\nu = 6$ $\nu = 50$
PB1 0.003680 0.003678 0.003703
PB2 0.000961 0.000979 0.001014
PB3 0.006884 0.006852 0.006954
PB4 1.411597 1.411941 1.412033
PB5 3.217966 3.201827 3.180822

In [16]:
f, ax = plt.subplots()

im_99pct_weights.sort_values(r'$\nu = 2$')[::-1].plot.bar(ax=ax)

labels = ['' for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

ax.yaxis.set_major_formatter(f_tex_pct_formatter)

plt.tick_params(axis='both', which='major', labelsize=labelsize)
plt.legend(fontsize=labelsize)

plt.show()



In [17]:
f, ax = plt.subplots()

im_99pct_weights.sort_values(r'$\nu = 2$')[::-1][:10].plot.bar(ax=ax)

labels = [tex_transf(item.get_text()) for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

for label in ax.get_xticklabels():
    label.set_rotation(0) 

ax.yaxis.set_major_formatter(f_tex_pct_formatter)

plt.tick_params(axis='both', which='major', labelsize=labelsize)
plt.legend(fontsize=labelsize)

plt.show()


$\nu = 6$


In [18]:
f, ax = plt.subplots()

im_99pct_weights[r'$\nu = 6$'].sort_values()[::-1].plot.bar(ax=ax, logy=True)

labels = ['' for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

ax.yaxis.set_major_formatter(f_scientific_tex_formatter2)

plt.tick_params(axis='both', which='major', labelsize=labelsize)
plt.legend(fontsize=labelsize)

plt.show()



In [22]:
f, ax = plt.subplots()

im_99pct_weights[r'$\nu = 6$'].sort_values()[::-1][:12].plot.bar(ax=ax)

labels = [tex_transf(item.get_text()) for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

for label in ax.get_xticklabels():
    label.set_rotation(0) 

ax.yaxis.set_major_formatter(f_tex_pct_formatter)

plt.tick_params(axis='both', which='major', labelsize=labelsize)
plt.legend(fontsize=labelsize)

plt.show()


IM 99.7 %


In [19]:
im_997pct_weights = im_997pct

for col in im_997pct_weights.columns:
    im_997pct_weights[col] = im_997pct_weights[col] / im_997pct_weights[col].sum() * 100.

im_997pct_weights.head()


Out[19]:
$\nu = 2$ $\nu = 6$ $\nu = 50$
PB1 0.003633 0.003616 0.003712
PB2 0.000940 0.000930 0.001006
PB3 0.006697 0.006740 0.006965
PB4 1.402566 1.407083 1.405505
PB5 3.240997 3.218709 3.155724

In [20]:
f, ax = plt.subplots()

im_997pct_weights.sort_values(r'$\nu = 2$')[::-1].plot.bar(ax=ax)

labels = ['' for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

ax.yaxis.set_major_formatter(f_tex_pct_formatter)

plt.tick_params(axis='both', which='major', labelsize=labelsize)
plt.legend(fontsize=labelsize)

plt.show()



In [21]:
f, ax = plt.subplots()

im_997pct_weights.sort_values(r'$\nu = 2$')[::-1][:10].plot.bar(ax=ax)

labels = [tex_transf(item.get_text()) for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

for label in ax.get_xticklabels():
    label.set_rotation(0) 

ax.yaxis.set_major_formatter(f_tex_pct_formatter)

plt.tick_params(axis='both', which='major', labelsize=labelsize)
plt.legend(fontsize=labelsize)

plt.show()