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)
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()
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()
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]:
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()
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()
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]:
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()