Last active
August 29, 2015 14:04
-
-
Save empet/63d55a61dfa0ccfa8ad3 to your computer and use it in GitHub Desktop.
Number of seats won by each country and political group in the European Parliament Elections, 2014
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:8790733655d68a48fb8ee3600ede2b036b74762e99d329a48c4edaf9c268d5cc" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "heading", | |
"level": 2, | |
"metadata": {}, | |
"source": [ | |
"<center>Number of seats won by each country and political group in the European Parliament Elections</center> " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"%matplotlib inline\n", | |
"import matplotlib.pyplot as plt\n", | |
"import pandas as pd\n", | |
"import numpy as np" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"Read data" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"xl = pd.ExcelFile(\"EuroParlamGroups.xls\")\n", | |
"print xl.sheet_names\n", | |
"\n", | |
"df = xl.parse(\"Sheet1\")\n", | |
"df" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"[u'Sheet1', u'Sheet2', u'Sheet3']\n" | |
] | |
}, | |
{ | |
"html": [ | |
"<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>COUNTRY</th>\n", | |
" <th>EPP</th>\n", | |
" <th>S&D</th>\n", | |
" <th>ECR</th>\n", | |
" <th>ALDE</th>\n", | |
" <th>GUE</th>\n", | |
" <th>GREENS</th>\n", | |
" <th>EFDD</th>\n", | |
" <th>NI</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0 </th>\n", | |
" <td> Austria</td>\n", | |
" <td> 5</td>\n", | |
" <td> 5</td>\n", | |
" <td> 0</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" <td> 3</td>\n", | |
" <td> 0</td>\n", | |
" <td> 4</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1 </th>\n", | |
" <td> Belgium</td>\n", | |
" <td> 4</td>\n", | |
" <td> 4</td>\n", | |
" <td> 4</td>\n", | |
" <td> 6</td>\n", | |
" <td> 0</td>\n", | |
" <td> 2</td>\n", | |
" <td> 0</td>\n", | |
" <td> 1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2 </th>\n", | |
" <td> Bulgaria</td>\n", | |
" <td> 7</td>\n", | |
" <td> 4</td>\n", | |
" <td> 2</td>\n", | |
" <td> 4</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3 </th>\n", | |
" <td> Croatia</td>\n", | |
" <td> 5</td>\n", | |
" <td> 2</td>\n", | |
" <td> 1</td>\n", | |
" <td> 2</td>\n", | |
" <td> 0</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4 </th>\n", | |
" <td> Cyprus</td>\n", | |
" <td> 2</td>\n", | |
" <td> 2</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 2</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5 </th>\n", | |
" <td> CzechR</td>\n", | |
" <td> 7</td>\n", | |
" <td> 4</td>\n", | |
" <td> 2</td>\n", | |
" <td> 4</td>\n", | |
" <td> 3</td>\n", | |
" <td> 0</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6 </th>\n", | |
" <td> Denmark</td>\n", | |
" <td> 1</td>\n", | |
" <td> 3</td>\n", | |
" <td> 4</td>\n", | |
" <td> 3</td>\n", | |
" <td> 1</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7 </th>\n", | |
" <td> Estonia</td>\n", | |
" <td> 1</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" <td> 3</td>\n", | |
" <td> 0</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8 </th>\n", | |
" <td> Finland</td>\n", | |
" <td> 3</td>\n", | |
" <td> 3</td>\n", | |
" <td> 2</td>\n", | |
" <td> 4</td>\n", | |
" <td> 1</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9 </th>\n", | |
" <td> France</td>\n", | |
" <td> 20</td>\n", | |
" <td> 13</td>\n", | |
" <td> 0</td>\n", | |
" <td> 7</td>\n", | |
" <td> 4</td>\n", | |
" <td> 6</td>\n", | |
" <td> 1</td>\n", | |
" <td> 23</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td> Germany</td>\n", | |
" <td> 34</td>\n", | |
" <td> 27</td>\n", | |
" <td> 8</td>\n", | |
" <td> 4</td>\n", | |
" <td> 8</td>\n", | |
" <td> 13</td>\n", | |
" <td> 0</td>\n", | |
" <td> 2</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td> Greece</td>\n", | |
" <td> 5</td>\n", | |
" <td> 4</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" <td> 6</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 5</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>12</th>\n", | |
" <td> Hungary</td>\n", | |
" <td> 12</td>\n", | |
" <td> 4</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 2</td>\n", | |
" <td> 0</td>\n", | |
" <td> 3</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>13</th>\n", | |
" <td> Ireland</td>\n", | |
" <td> 4</td>\n", | |
" <td> 1</td>\n", | |
" <td> 1</td>\n", | |
" <td> 1</td>\n", | |
" <td> 4</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>14</th>\n", | |
" <td> Italy</td>\n", | |
" <td> 17</td>\n", | |
" <td> 31</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 3</td>\n", | |
" <td> 0</td>\n", | |
" <td> 17</td>\n", | |
" <td> 5</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>15</th>\n", | |
" <td> Latvia</td>\n", | |
" <td> 4</td>\n", | |
" <td> 1</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 1</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>16</th>\n", | |
" <td> Lithuania</td>\n", | |
" <td> 2</td>\n", | |
" <td> 2</td>\n", | |
" <td> 1</td>\n", | |
" <td> 3</td>\n", | |
" <td> 0</td>\n", | |
" <td> 1</td>\n", | |
" <td> 2</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>17</th>\n", | |
" <td> Luxembourg</td>\n", | |
" <td> 3</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>18</th>\n", | |
" <td> Malta</td>\n", | |
" <td> 3</td>\n", | |
" <td> 3</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>19</th>\n", | |
" <td> Netherlands</td>\n", | |
" <td> 5</td>\n", | |
" <td> 3</td>\n", | |
" <td> 2</td>\n", | |
" <td> 7</td>\n", | |
" <td> 3</td>\n", | |
" <td> 2</td>\n", | |
" <td> 0</td>\n", | |
" <td> 4</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>20</th>\n", | |
" <td> Poland</td>\n", | |
" <td> 23</td>\n", | |
" <td> 5</td>\n", | |
" <td> 19</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 4</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>21</th>\n", | |
" <td> Portugal</td>\n", | |
" <td> 7</td>\n", | |
" <td> 8</td>\n", | |
" <td> 0</td>\n", | |
" <td> 2</td>\n", | |
" <td> 4</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>22</th>\n", | |
" <td> Romania</td>\n", | |
" <td> 15</td>\n", | |
" <td> 16</td>\n", | |
" <td> 0</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>23</th>\n", | |
" <td> Slovakia</td>\n", | |
" <td> 6</td>\n", | |
" <td> 4</td>\n", | |
" <td> 2</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>24</th>\n", | |
" <td> Slovenia</td>\n", | |
" <td> 5</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" <td> 1</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>25</th>\n", | |
" <td> Spain</td>\n", | |
" <td> 17</td>\n", | |
" <td> 14</td>\n", | |
" <td> 0</td>\n", | |
" <td> 8</td>\n", | |
" <td> 11</td>\n", | |
" <td> 4</td>\n", | |
" <td> 0</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>26</th>\n", | |
" <td> Sweden</td>\n", | |
" <td> 4</td>\n", | |
" <td> 6</td>\n", | |
" <td> 0</td>\n", | |
" <td> 3</td>\n", | |
" <td> 1</td>\n", | |
" <td> 4</td>\n", | |
" <td> 2</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>27</th>\n", | |
" <td> UK</td>\n", | |
" <td> 0</td>\n", | |
" <td> 20</td>\n", | |
" <td> 20</td>\n", | |
" <td> 1</td>\n", | |
" <td> 1</td>\n", | |
" <td> 6</td>\n", | |
" <td> 24</td>\n", | |
" <td> 1</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 2, | |
"text": [ | |
" COUNTRY EPP S&D ECR ALDE GUE GREENS EFDD NI\n", | |
"0 Austria 5 5 0 1 0 3 0 4\n", | |
"1 Belgium 4 4 4 6 0 2 0 1\n", | |
"2 Bulgaria 7 4 2 4 0 0 0 0\n", | |
"3 Croatia 5 2 1 2 0 1 0 0\n", | |
"4 Cyprus 2 2 0 0 2 0 0 0\n", | |
"5 CzechR 7 4 2 4 3 0 1 0\n", | |
"6 Denmark 1 3 4 3 1 1 0 0\n", | |
"7 Estonia 1 1 0 3 0 1 0 0\n", | |
"8 Finland 3 3 2 4 1 1 0 0\n", | |
"9 France 20 13 0 7 4 6 1 23\n", | |
"10 Germany 34 27 8 4 8 13 0 2\n", | |
"11 Greece 5 4 1 0 6 0 0 5\n", | |
"12 Hungary 12 4 0 0 0 2 0 3\n", | |
"13 Ireland 4 1 1 1 4 0 0 0\n", | |
"14 Italy 17 31 0 0 3 0 17 5\n", | |
"15 Latvia 4 1 1 0 0 1 1 0\n", | |
"16 Lithuania 2 2 1 3 0 1 2 0\n", | |
"17 Luxembourg 3 1 0 1 0 1 0 0\n", | |
"18 Malta 3 3 0 0 0 0 0 0\n", | |
"19 Netherlands 5 3 2 7 3 2 0 4\n", | |
"20 Poland 23 5 19 0 0 0 0 4\n", | |
"21 Portugal 7 8 0 2 4 0 0 0\n", | |
"22 Romania 15 16 0 1 0 0 0 0\n", | |
"23 Slovakia 6 4 2 1 0 0 0 0\n", | |
"24 Slovenia 5 1 0 1 0 1 0 0\n", | |
"25 Spain 17 14 0 8 11 4 0 0\n", | |
"26 Sweden 4 6 0 3 1 4 2 0\n", | |
"27 UK 0 20 20 1 1 6 24 1" | |
] | |
} | |
], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"#EuGroupsCols={'EPP': '#000762', 'S&D': '#c21200' , 'ECR': '#0074a1', 'ALDE': '#edb400',\\\n", | |
"# 'GUE-NGL': '#8a0800', 'GREENS-EFA': '#007200', 'EFDD':'#305268' , 'NI': '#a09f9f'}\n", | |
"\n", | |
"Groups=['EPP', 'S&D', 'ECR', 'ALDE', 'GUE/NGL','GREENS/EFA', 'EFDD', 'NI']\n", | |
"#Colour id for each Political Group:\n", | |
"Cols=['#000762','#c21200' , '#0074a1','#edb400' ,'#8a0800','#007200' ,'#305268' , '#a09f9f']\n", | |
"\n", | |
"Countries=list(df['COUNTRY'])\n" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 3 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"European Parliament election results for each country and political group" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import plotly.plotly as py \n", | |
"import plotly.tools as tls \n", | |
"from plotly.graph_objs import *" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 4 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"\n", | |
"\n", | |
"def make_Bars(sbplt, k, y_in): \n", | |
" return Bar(\n", | |
" x=Groups, \n", | |
" y=y_in, \n", | |
" marker=Marker(\n", | |
" color=Cols),\n", | |
" xaxis= 'x{}'.format(sbplt), # bind coordinate to x-axis of subplot\n", | |
" yaxis= 'y{}'.format(sbplt), # bind coordinate to y-axis of subplot\n", | |
" name=Countries[k]\n", | |
" )\n", | |
" " | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 5 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"axis_style = dict(\n", | |
" ticks='', \n", | |
" showticklabels=False, \n", | |
" showgrid=False,\n", | |
" zeroline=False,\n", | |
" showline=True,\n", | |
" mirror=True) \n", | |
"\n", | |
"\n", | |
"def make_XAxis():\n", | |
" xaxis = XAxis() \n", | |
" xaxis.update(axis_style) \n", | |
" return xaxis\n", | |
"\n", | |
"\n", | |
"def make_YAxis(y_in):\n", | |
" yaxis = YAxis(range=[0,max(y_in)+2]) \n", | |
" yaxis.update(axis_style) \n", | |
" return yaxis\n", | |
"\n", | |
"def make_sbplt_anno(sbplt_in,y_in,country): #annotations for subplots\n", | |
" return Annotation(\n", | |
" x= 2, \n", | |
" y= max(y_in)+2, \n", | |
" text= country, \n", | |
" align='center', \n", | |
" font= Font(size=14), \n", | |
" showarrow=False, \n", | |
" xanchor='center', \n", | |
" xref= 'x{}'.format(sbplt_in), \n", | |
" yref= 'y{}'.format(sbplt_in)\n", | |
" ) \n", | |
"\n", | |
" \n", | |
"\n", | |
" " | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 6 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"We are setting the dimensions of the grid of subplots and generate the grid:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"nr_rows=7\n", | |
"nr_cols=4\n", | |
"\n", | |
"figure = tls.get_subplots(\n", | |
" rows=nr_rows,\n", | |
" columns=nr_cols,\n", | |
" horizontal_spacing=0.025,\n", | |
" vertical_spacing=0.025,\n", | |
" print_grid=True)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"This is the format of your plot grid!\n", | |
"[25]\t[26]\t[27]\t[28]\t\n", | |
"[21]\t[22]\t[23]\t[24]\t\n", | |
"[17]\t[18]\t[19]\t[20]\t\n", | |
"[13]\t[14]\t[15]\t[16]\t\n", | |
"[9]\t[10]\t[11]\t[12]\t\n", | |
"[5]\t[6]\t[7]\t[8]\t\n", | |
"[1]\t[2]\t[3]\t[4]\t\n", | |
"\n" | |
] | |
} | |
], | |
"prompt_number": 7 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"We define the list of subplots in the grid:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"sbp=[(nr_rows-(i+1))*nr_cols+j+1 for i in range(nr_rows) for j in range(nr_cols)]\n", | |
"#list of subplots row by row, from upper-left to lower-right corner\n", | |
"print sbp" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"[25, 26, 27, 28, 21, 22, 23, 24, 17, 18, 19, 20, 13, 14, 15, 16, 9, 10, 11, 12, 5, 6, 7, 8, 1, 2, 3, 4]\n" | |
] | |
} | |
], | |
"prompt_number": 8 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"and update the figure features:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"pl_width=800 \n", | |
"pl_height=1200 \n", | |
"\n", | |
"figure['layout'].update(showlegend=False, \n", | |
" hovermode='closest', \n", | |
" autosize=False, \n", | |
" width=pl_width, \n", | |
" height=pl_height) \n", | |
"\n", | |
"title = 'Number of Seats won by the Political Groups in the European Parliament'\n", | |
"figure['layout'].update(title=title, \n", | |
" font= Font(family=\"Open Sans, sans-serif\")) \n" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 9 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"anno_text=\"Data source:\\\n", | |
"<a href='http://www.results-elections2014.eu/en/country-introduction-2014.html'>[1]</a>\"\n", | |
"\n", | |
"figure['layout']['annotations'] = Annotations([\n", | |
" Annotation(\n", | |
" showarrow=False, \n", | |
" text=anno_text, \n", | |
" xref='paper', \n", | |
" yref='paper', \n", | |
" x=0, \n", | |
" y=-0.075, \n", | |
" xanchor='left', \n", | |
" yanchor='bottom', \n", | |
" font=Font(\n", | |
" size=14 )\n", | |
" )\n", | |
"]) " | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 10 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Finally we map the data for each country to a subplot in the grid/list:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"for s in sbp:\n", | |
" k=sbp.index(s)\n", | |
" y_inn=df.ix[k].values\n", | |
" y_in=y_inn[1:].tolist()\n", | |
" \n", | |
" figure['data'] += [make_Bars(s, k, y_in)]\n", | |
" figure['layout'].update({'xaxis{}'.format(s): make_XAxis()})\n", | |
" figure['layout'].update({'yaxis{}'.format(s): make_YAxis(y_in)})\n", | |
" figure['layout']['annotations'] += [make_sbplt_anno(s,y_in, Countries[k])] \n", | |
" " | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 11 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"\n", | |
"for s in range(1,5):\n", | |
" xaxis_splt = figure['layout']['xaxis{}'.format(s)] \n", | |
" xaxis_splt.update(title='Political Groups')\n", | |
" \n", | |
"for s in range(1,26, 4): \n", | |
" yaxis_splt = figure['layout']['yaxis{}'.format(s)] \n", | |
" yaxis_splt.update(title='Nr of seats') " | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 12 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"py.sign_in(\"empet\", \"my_api_key\")" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 13 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"py.iplot(figure, filename='EU-Parliam-Political-Groups', width=800,\n", | |
" height=1200) " | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"html": [ | |
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\"seamless=\"seamless\" src=\"https://plot.ly/~empet/36/775/1175\" height=\"1200\" width=\"800\"></iframe>" | |
], | |
"metadata": {}, | |
"output_type": "display_data", | |
"text": [ | |
"<IPython.core.display.HTML at 0xc0e5438>" | |
] | |
} | |
], | |
"prompt_number": 14 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"E Petrisor, UPT" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"from IPython.core.display import HTML\n", | |
"def css_styling():\n", | |
" styles = open(\"./styles/custom.css\", \"r\").read()\n", | |
" return HTML(styles)\n", | |
"css_styling()" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"html": [ | |
"<style>\n", | |
" div.cell{\n", | |
" width:800px;\n", | |
" margin-left:16% !important;\n", | |
" margin-right:auto;\n", | |
" }\n", | |
" h1 {\n", | |
" font-family: 'Alegreya Sans', sans-serif;\n", | |
" }\n", | |
" \n", | |
" h2 {\n", | |
" font-family: 'Fenix', serif;\n", | |
" text-indent:1em;\n", | |
" }\n", | |
" .text_cell_render h2 {\n", | |
" font-weight: 200;\n", | |
" font-size: 20pt;\n", | |
" line-height: 100%;\n", | |
" margin-bottom: 1.5em;\n", | |
" margin-top: 0.5em;\n", | |
" display: block;\n", | |
" }\n", | |
" h3 {\n", | |
" font-family: 'Fenix', serif;\n", | |
" %margin-top:12px;\n", | |
" %margin-bottom: 3px;\n", | |
" }\n", | |
" .text_cell_render h3 {\n", | |
" font-weight: 300;\n", | |
" font-size: 18pt;\n", | |
" line-height: 100%;\n", | |
" margin-bottom: 0.5em;\n", | |
" margin-top: 2em;\n", | |
" display: block;\n", | |
" }\n", | |
" h4 {\n", | |
" font-family: 'Fenix', serif;\n", | |
" }\n", | |
" .text_cell_render h4 {\n", | |
" font-weight: 300;\n", | |
" font-size: 16pt;\n", | |
" margin-bottom: 0.5em;\n", | |
" margin-top: 0.5em;\n", | |
" display: block;\n", | |
" }\n", | |
" h5 {\n", | |
" font-family: 'Alegreya Sans', sans-serif;\n", | |
" }\n", | |
" .text_cell_render h5 {\n", | |
" font-weight: 300;\n", | |
" font-style: normal;\n", | |
" font-size: 16pt;\n", | |
" margin-bottom: 0em;\n", | |
" margin-top: 1.5em;\n", | |
" display: block;\n", | |
" }\n", | |
" \n", | |
" div.text_cell_render{\n", | |
" %font-family: Computer Modern, \"Helvetica Neue\", Arial, Helvetica, Geneva, sans-serif;\n", | |
" font-family: 'Alegreya Sans',Computer Modern, \"Helvetica Neue\", Arial, Helvetica, Geneva, sans-serif;\n", | |
" line-height: 145%;\n", | |
" font-size: 130%;\n", | |
" width:800px;\n", | |
" margin-left:auto;\n", | |
" margin-right:auto;\n", | |
" }\n", | |
" blockquote{\n", | |
" display:block;\n", | |
" background: #f3f3f3;\n", | |
" font-family: \"Open sans\",verdana,arial,sans-serif;\n", | |
" width:610px;\n", | |
" padding: 15px 15px 15px 15px;\n", | |
" text-align:justify;\n", | |
" text-justify:inter-word;\n", | |
" }\n", | |
" blockquote p {\n", | |
" margin-bottom: 0;\n", | |
" line-height: 125%;\n", | |
" font-size: 100%;\n", | |
" }\n", | |
" \n", | |
" .prompt{\n", | |
" display: None;\n", | |
" }\n", | |
" .warning{\n", | |
" color: rgb( 240, 20, 20 )\n", | |
" } \n", | |
"</style>\n", | |
"<script>\n", | |
" MathJax.Hub.Config({\n", | |
" TeX: {\n", | |
" extensions: [\"AMSmath.js\"]\n", | |
" },\n", | |
" tex2jax: {\n", | |
" inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n", | |
" displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n", | |
" },\n", | |
" displayAlign: 'center', // Change this to 'center' to center equations.\n", | |
" \"HTML-CSS\": {\n", | |
" styles: {'.MathJax_Display': {\"margin\": 4}}\n", | |
" }\n", | |
" });\n", | |
"</script>\n" | |
], | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 1, | |
"text": [ | |
"<IPython.core.display.HTML at 0x32ac6d8>" | |
] | |
} | |
], | |
"prompt_number": 1 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment