MODICE v04 area by country, 2000-2014


In [1]:
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [62]:
filename = 'modice_v4_3strikes_by_country_by_yr.txt'
df3 = pd.read_csv( filename, delim_whitespace=True, index_col=0 )
df3


Out[62]:
Kazakhstan Kyrgyz_Republic Tajikistan Turkmenistan Uzbekistan
Year
2000 2417.5 9358.7 9653.0 470.5 1254.5
2001 2118.9 8015.8 8792.0 137.6 1289.2
2002 1972.9 7677.3 10175.3 351.8 792.5
2003 1849.9 7960.0 11372.6 354.6 1115.8
2004 1793.3 8224.4 12614.0 472.9 1060.4
2005 1809.1 8004.4 10274.4 423.1 1082.1
2006 1395.7 6082.8 8474.3 363.8 1030.1
2007 1394.2 5837.0 7943.7 429.7 988.3
2008 1546.4 5982.1 7297.3 305.2 1052.9
2009 2579.8 12104.4 13059.8 310.4 1213.3
2010 1741.7 8787.1 13103.6 321.8 1117.1
2011 1767.1 7328.2 7874.3 327.6 1026.7
2012 1470.2 6830.4 11431.6 308.0 1009.8
2013 1820.1 5868.1 8339.1 140.8 1007.6
2014 1356.9 5669.4 9083.1 217.0 1037.4

Reorder columns, descending area

Use the first row of data to order the columns in descending area order


In [63]:
sorted_col_index = df3.ix[df3.first_valid_index()].argsort()[::-1]
print sorted_col_index
df3 = df3[sorted_col_index]
df3


Uzbekistan         2
Turkmenistan       1
Tajikistan         0
Kyrgyz_Republic    4
Kazakhstan         3
Name: 2000, dtype: int64
Out[63]:
Tajikistan Kyrgyz_Republic Kazakhstan Uzbekistan Turkmenistan
Year
2000 9653.0 9358.7 2417.5 1254.5 470.5
2001 8792.0 8015.8 2118.9 1289.2 137.6
2002 10175.3 7677.3 1972.9 792.5 351.8
2003 11372.6 7960.0 1849.9 1115.8 354.6
2004 12614.0 8224.4 1793.3 1060.4 472.9
2005 10274.4 8004.4 1809.1 1082.1 423.1
2006 8474.3 6082.8 1395.7 1030.1 363.8
2007 7943.7 5837.0 1394.2 988.3 429.7
2008 7297.3 5982.1 1546.4 1052.9 305.2
2009 13059.8 12104.4 2579.8 1213.3 310.4
2010 13103.6 8787.1 1741.7 1117.1 321.8
2011 7874.3 7328.2 1767.1 1026.7 327.6
2012 11431.6 6830.4 1470.2 1009.8 308.0
2013 8339.1 5868.1 1820.1 1007.6 140.8
2014 9083.1 5669.4 1356.9 1037.4 217.0

Get 1 and 2strike data also:


In [64]:
filename = 'modice_v4_2strikes_by_country_by_yr.txt'
df2 = pd.read_csv( filename, delim_whitespace=True, index_col=0 )
df2 = df2[sorted_col_index]
filename = 'modice_v4_1strikes_by_country_by_yr.txt'
df1 = pd.read_csv( filename, delim_whitespace=True, index_col=0 )
df1 = df1[sorted_col_index]

In [65]:
print df1
print df2


      Tajikistan  Kyrgyz_Republic  Kazakhstan  Uzbekistan  Turkmenistan
Year                                                                   
2000      5922.6           6156.0      1591.1      1101.0         276.7
2001      5711.6           5179.7      1309.6      1037.7          51.9
2002      6939.3           5089.1      1303.2       552.7         168.7
2003      7967.3           5473.6      1241.6       759.5         196.8
2004      9105.6           5826.1      1193.9       700.9         295.4
2005      6907.5           5306.8      1090.3       873.0         282.5
2006      5663.6           4016.7       871.7       713.1         209.7
2007      5324.4           4024.6       849.8       728.6         281.8
2008      4427.3           3758.2      1007.4       998.4         166.6
2009      8661.5           8164.1      1654.6       944.3         156.3
2010      7693.2           5527.0      1095.6       797.0         168.5
2011      4572.0           4915.0      1178.0       853.9         192.8
2012      8424.9           4399.2       982.7       765.7         170.2
2013      6214.4           4038.4      1221.6       695.3          67.4
2014      6491.5           3654.8       822.8       849.6         121.9
      Tajikistan  Kyrgyz_Republic  Kazakhstan  Uzbekistan  Turkmenistan
Year                                                                   
2000      8282.4           7952.9      2066.7      1192.4         403.1
2001      7692.3           6771.6      1764.3      1216.5          99.6
2002      8927.0           6571.6      1685.9       692.7         277.6
2003     10018.8           6872.1      1565.7       980.1         281.2
2004     11248.5           7166.0      1505.8       915.7         407.2
2005      8972.1           6831.7      1463.3       988.9         367.9
2006      7364.1           5196.2      1145.0       928.4         298.6
2007      6926.0           5071.5      1152.7       882.0         375.7
2008      6118.6           5041.3      1319.3      1034.2         254.6
2009     11341.9          10376.8      2151.1      1144.6         241.7
2010     11009.8           7361.5      1452.0       981.4         266.8
2011      6518.8           6268.9      1509.7       961.7         274.1
2012     10218.0           5793.0      1265.4       947.1         253.9
2013      7499.5           5097.7      1553.9       914.2         109.7
2014      8037.7           4819.3      1118.6       983.4         178.2

In [66]:
my_colors = list(['b','g','r','c','m'])
fig, axes = plt.subplots(nrows=3, ncols=1, sharex=True, figsize=(10,10))

df3.plot(ax=axes[0], style='-o', color=my_colors)
axes[0].legend(bbox_to_anchor=(1.3,1.0))
axes[0].set(title="MODICE(3strike) by Country", ylabel='MODICE area ($km^2$)' )

df2.plot(ax=axes[1], style='-o', color=my_colors)
axes[1].legend(bbox_to_anchor=(1.3,1.0))
axes[1].set(title="MODICE(2strike) by Country", ylabel='MODICE area ($km^2$)' )

df1.plot(ax=axes[2], style='-o', color=my_colors)
axes[2].legend(bbox_to_anchor=(1.3,1.0))
axes[2].set(title="MODICE(1strike) by Country", ylabel='MODICE area ($km^2$)' )


Out[66]:
[<matplotlib.text.Text at 0x1097f2390>, <matplotlib.text.Text at 0x10a115e90>]

Just look at detail on three lowest lines:


In [67]:
subdf3 = df3[['Kazakhstan','Uzbekistan','Turkmenistan']]
subdf2 = df2[['Kazakhstan','Uzbekistan','Turkmenistan']]
subdf1 = df1[['Kazakhstan','Uzbekistan','Turkmenistan']]

In [68]:
my_sub_colors = my_colors[2:]

fig, axes = plt.subplots(nrows=3, ncols=1, sharex=True, figsize=(10,10))

subdf3.plot(ax=axes[0], style='-o', color=my_sub_colors)
axes[0].legend(bbox_to_anchor=(1.3,1.0))
axes[0].set(title="MODICE(3strike) by Country", ylabel='MODICE area ($km^2$)' )

subdf2.plot(ax=axes[1], style='-o', color=my_sub_colors)
axes[1].legend(bbox_to_anchor=(1.3,1.0))
axes[1].set(title="MODICE(2strike) by Country", ylabel='MODICE area ($km^2$)' )

subdf1.plot(ax=axes[2], style='-o', color=my_sub_colors)
axes[2].legend(bbox_to_anchor=(1.3,1.0))
axes[2].set(title="MODICE(1strike) by Country", ylabel='MODICE area ($km^2$)' )


Out[68]:
[<matplotlib.text.Text at 0x10b505250>, <matplotlib.text.Text at 0x10b512550>]

In [ ]: