06-04-2016-plot-aggregate-histograms



In [4]:
%matplotlib inline
import pandas as pd
import numpy as np
import os
import seaborn as sns
import matplotlib.pyplot as plt
sns.set()

In [5]:
os.listdir('../clean_data/')


Out[5]:
['agg_hist_2012Q4.csv',
 'agg_hist_2014Q4.csv',
 'agg_hist_2015Q1.csv',
 'agg_hist_2015Q2.csv',
 'agg_hist_2015Q3.csv',
 'agg_hist_2015Q4.csv',
 'agg_hist_2016Q1.csv',
 'agg_hist_2016Q2.csv',
 'Point_and_Ind_Uncertainty.xlsx',
 'PointForecasts.xlsx',
 'SPF_aggregate_histogram.xlsx',
 'SPF_aggregate_uncertainty.xlsx',
 'SPF_time_series.xlsx']

In [6]:
df1 = pd.read_excel('../clean_data/SPF_aggregate_histogram.xlsx',sheetname='2016Q1',header = 0,index_col=1)
df1.head()


Out[6]:
source [-2.0,-1.1] [-1.0,-0.6] [-0.5,-0.1] [0.0,0.4] [0.5,0.9] [1.0,1.4] [1.5,1.9] [2.0,2.4] [2.5,2.9] [3.0,3.4] [3.5,3.9] [4.0,5.0]
target
2016 2016-Q1 0.413101 1.398154 6.563698 20.755563 36.195539 24.786644 7.592633 1.621901 0.447736 0.153583 0.051039 0.020409
2016Dec NaN 0.195111 0.806320 4.042026 13.342081 28.040684 29.923766 15.302813 5.559588 1.886260 0.725573 0.132911 0.042867
2017 NaN 0.156856 0.477735 1.518767 6.433687 15.147962 29.303042 32.341059 10.275199 3.194858 0.981854 0.120430 0.048552
2017Dec NaN 0.185830 0.564403 1.435289 6.079712 14.309872 26.287529 31.065046 12.809149 4.601514 2.036121 0.469910 0.155625
2018 NaN 0.257009 0.444428 1.476107 5.034666 12.351745 23.639347 33.018521 16.313100 5.195082 1.649630 0.443358 0.177007

In [7]:
mask  = df1.columns.str.contains(',')
mask


Out[7]:
array([False,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True], dtype=bool)

In [8]:
h1 = df1.loc['2016',mask]
h1


Out[8]:
[-2.0,-1.1]     0.4131005
[-1.0,-0.6]      1.398154
[-0.5,-0.1]      6.563698
[0.0,0.4]        20.75556
[0.5,0.9]        36.19554
[1.0,1.4]        24.78664
[1.5,1.9]        7.592633
[2.0,2.4]        1.621901
[2.5,2.9]       0.4477361
[3.0,3.4]       0.1535832
[3.5,3.9]      0.05103885
[4.0,5.0]      0.02040868
Name: 2016, dtype: object

In [9]:
hdf1 = pd.DataFrame(h1)
hdf1['id'] = np.arange(0,len(h1))
hdf1['ints'] = hdf1.index
hdf1.set_index('id',inplace=True)
hdf1


Out[9]:
2016 ints
id
0 0.4131005 [-2.0,-1.1]
1 1.398154 [-1.0,-0.6]
2 6.563698 [-0.5,-0.1]
3 20.75556 [0.0,0.4]
4 36.19554 [0.5,0.9]
5 24.78664 [1.0,1.4]
6 7.592633 [1.5,1.9]
7 1.621901 [2.0,2.4]
8 0.4477361 [2.5,2.9]
9 0.1535832 [3.0,3.4]
10 0.05103885 [3.5,3.9]
11 0.02040868 [4.0,5.0]

In [10]:
hdf1['source'] = '2016Q1'
hdf1.rename(columns={'2016':'p'},inplace=True)

In [11]:
df2 = pd.read_excel('../clean_data/SPF_aggregate_histogram.xlsx',sheetname='2015Q4',header = 0,index_col=1)
df2.head()


Out[11]:
source [-2.0,-1.1] [-1.0,-0.6] [-0.5,-0.1] [0.0,0.4] [0.5,0.9] [1.0,1.4] [1.5,1.9] [2.0,2.4] [2.5,2.9] [3.0,3.4] [3.5,3.9] [4.0,5.0]
target
2015 2015-Q4 0.602000 2.276000 24.296903 63.002736 7.678361 1.576000 0.398000 0.098000 0.040000 0.022000 0.010000 0.000000
2016 NaN 0.219028 0.829607 3.714362 11.753718 29.132909 34.504901 14.095859 4.038049 1.155750 0.367736 0.124080 0.064002
2016Sep NaN 0.366086 0.954973 4.393809 11.584200 27.678981 30.215566 15.823224 5.869419 2.134730 0.655915 0.233833 0.089264
2017 NaN 0.284444 0.653333 1.560000 5.448889 11.971111 26.715556 33.200000 14.075556 4.217778 1.426667 0.326667 0.120000
2017Sep NaN 0.237143 0.697143 1.568571 5.814286 12.582857 26.068571 31.622857 13.760000 4.948571 1.934286 0.522857 0.242857

In [12]:
mask  = df2.columns.str.contains(',')
mask


Out[12]:
array([False,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True], dtype=bool)

In [13]:
h2 = df2.loc['2016',mask]
h2


Out[13]:
[-2.0,-1.1]     0.2190281
[-1.0,-0.6]      0.829607
[-0.5,-0.1]      3.714362
[0.0,0.4]        11.75372
[0.5,0.9]        29.13291
[1.0,1.4]         34.5049
[1.5,1.9]        14.09586
[2.0,2.4]        4.038049
[2.5,2.9]         1.15575
[3.0,3.4]       0.3677355
[3.5,3.9]       0.1240798
[4.0,5.0]      0.06400194
Name: 2016, dtype: object

In [14]:
hdf2 = pd.DataFrame(h2)
hdf2['id'] = np.arange(0,len(h2))
hdf2['ints'] = hdf2.index
hdf2 = hdf2.set_index('id')
hdf2


Out[14]:
2016 ints
id
0 0.2190281 [-2.0,-1.1]
1 0.829607 [-1.0,-0.6]
2 3.714362 [-0.5,-0.1]
3 11.75372 [0.0,0.4]
4 29.13291 [0.5,0.9]
5 34.5049 [1.0,1.4]
6 14.09586 [1.5,1.9]
7 4.038049 [2.0,2.4]
8 1.15575 [2.5,2.9]
9 0.3677355 [3.0,3.4]
10 0.1240798 [3.5,3.9]
11 0.06400194 [4.0,5.0]

In [15]:
hdf2['source'] = '2015Q4'
hdf2.rename(columns={'2016':'p'},inplace=True)

In [16]:
hdf1.head()


Out[16]:
p ints source
id
0 0.4131005 [-2.0,-1.1] 2016Q1
1 1.398154 [-1.0,-0.6] 2016Q1
2 6.563698 [-0.5,-0.1] 2016Q1
3 20.75556 [0.0,0.4] 2016Q1
4 36.19554 [0.5,0.9] 2016Q1

In [ ]:


In [ ]:


In [17]:
df = pd.concat([hdf1,hdf2],join='inner',ignore_index=True)
df.shape


Out[17]:
(24, 3)

In [18]:
df


Out[18]:
p ints source
0 0.4131005 [-2.0,-1.1] 2016Q1
1 1.398154 [-1.0,-0.6] 2016Q1
2 6.563698 [-0.5,-0.1] 2016Q1
3 20.75556 [0.0,0.4] 2016Q1
4 36.19554 [0.5,0.9] 2016Q1
5 24.78664 [1.0,1.4] 2016Q1
6 7.592633 [1.5,1.9] 2016Q1
7 1.621901 [2.0,2.4] 2016Q1
8 0.4477361 [2.5,2.9] 2016Q1
9 0.1535832 [3.0,3.4] 2016Q1
10 0.05103885 [3.5,3.9] 2016Q1
11 0.02040868 [4.0,5.0] 2016Q1
12 0.2190281 [-2.0,-1.1] 2015Q4
13 0.829607 [-1.0,-0.6] 2015Q4
14 3.714362 [-0.5,-0.1] 2015Q4
15 11.75372 [0.0,0.4] 2015Q4
16 29.13291 [0.5,0.9] 2015Q4
17 34.5049 [1.0,1.4] 2015Q4
18 14.09586 [1.5,1.9] 2015Q4
19 4.038049 [2.0,2.4] 2015Q4
20 1.15575 [2.5,2.9] 2015Q4
21 0.3677355 [3.0,3.4] 2015Q4
22 0.1240798 [3.5,3.9] 2015Q4
23 0.06400194 [4.0,5.0] 2015Q4

In [20]:
plt.figure()
g = sns.barplot(x='ints', y='p',hue='source',data=df);
locs, labels = plt.xticks()
plt.setp(labels, rotation=45)
g.set_ylabel('probability')
g.set_xlabel('interval')
g.set_title('Aggregate histograms: HICP inflation in 2016')

plt.tight_layout()
#plt.savefig('../figures/2016-04-06' + '-aggregate_histograms_2016.png')
#plt.savefig('../figures/2016-04-06' + '-aggregate_histograms_2016.pdf')
#plt.savefig('../figures/2016-04-06' + 'ggregate_histograms_2016.eps')
#plt.savefig('../figures/2016-04-06' + '-aggregate_histograms_2016.svg')
plt.draw()



In [73]:
plt.savefig("../figures/2016-04-06" + "-aggregate_histograms_2016.png")


<matplotlib.figure.Figure at 0xadd79e8>

In [75]:
plt.savefig("../figures/2016-04-06" + "-aggregate_histograms_2016.jpeg")


<matplotlib.figure.Figure at 0xa821d68>

In [77]:
plt


Out[77]:
<module 'matplotlib.pyplot' from 'C:\\Users\\EEU227\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\matplotlib\\pyplot.py'>

In [78]:
plt.savefig('myfig')


<matplotlib.figure.Figure at 0xa890d30>

In [ ]: