Tag Archives: python

How much EU is there around Brussels?

Two years ago Andy Woodruff wrote a fun blog entry about land area plotted by latitude and longitude, where he proceeded to squish the continents’ area along the X and Y axes (just like Bill Rankin did with Earth’s population earlier).

Andy’s two images combined

His post was the catalyst for me to try mapping the next step: squishing an area towards a point.

In fact, there was an a question floating around my brain earlier about the EU: “If I sit in Brussels, the de facto capital, how much union is there in each direction?”

It might feel like the answer is : “Look at a map!”, but due to history and geography, the EU’s territory snakes around the Baltic Sea, the Western Balkans candidate countries, not to mention that big hole called Switzerland. On the other hand you have detached areas, such as the UK and Ireland, or Cyprus.

So I plotted the EU onto a an Lambert azimuthal equal-area projection where I took Brussels as the center, thus lines spreading out radially from the center wouldn’t be distorted, while the areas of the countries stayed constant no matter how far from the center. To add a bit of color, without making one for each of the 28 member state, I colored them by the year they joined the EU.EU Melt - Before

I then wrote a python script that in essence iterated along each line starting in the chosen center and ending on an outer pixels, and moved the colored pixels as much as possible towards the center. For finding the relevant pixels I used this adaptation of Xiaolin Wu’s algorithm, and it took some fine tuning before I got a good result.

So here it is: Brussels sucking the EU towards it…

EU Melt - After sq

And in .gif version (click to enlarge):Gif EU Melt

As one can see, I only used the main European territories of the EU plus the Macaronesian Outermost Regions (Azores, Madeira, Canary Islands), due to their geographical proximity to Europe, but I ignored the other OMRs such as French Guyana, Reunion or the ones in the Antilles.

In the end, the resulting shape is somewhat Rorschach-ish, and to me it kinda looks like a bat, or a sad bumblebee. I wonder what others see?

Rorschach test


The Average Face of the European Parliament

Inspired by similar works, such as Giuseppe Sollazzo’s “I calculated the average face of the UK Member of Parliament” and redditor /u/ everest4ever’s “Average face of the Chinese Bureaucracy“, I decided to calculate the average face for the Members of the European Parliament, and see what our average representative in Brussels/Strasbourg looks like. The following results are valid for the EP as it was on 1 November 2017.

The average MEP

Average MEP
As expected by the 2-to-1 male to female ratio, the average face looks like a somewhat feminine middle aged man. White, but not too pale, light hazel eyes, light brown hair. Men tend to have greying hair and hazel eyes and a more reserved smile than women. Female MEPs have lighter eyes, but darker hair, probably because dying to hide greying hair is more frequent among women.

If I had to guess where they are from, I would probably say somewhere in the Alpine region/Central Europe – southern Germany, Austria, maybe northernmost Italy, Slovenia or Czechia.

By Political Group

First of all, if you are not familiar with the Political Groups of the European Parliament, click here for a quick rundown of the basics.

All MEPs
Average faces, when broken down by political group, tend to highlight the gender (in)balance in each group. For example, the small Non-Inscrit group obviously has the lowest female-to-male ratio in the EP (under 20%) while the leftist GUE-NGL – quite androginous here – has the highest (50%).

By Gender

Female MEPs
The Female MEP photos tend to show a lot of diferences among themselves. The Conservatives – dominated by UK and Polish MEPs – and the Nationalist ENF – dominated by France’s Front National – are the blondest, with the latter appearing to have a higher average age.

Due to only having 3 female MEPs in the Non-Inscrit group, the result came out pretty creepy. I therefore averaged it with its own mirror image to smooth out the “lizard overlord” vibe of the original.

Male MEPs.png

Male MEP photos tend to resemble each other more. Even so there is some variation, probably influenced by its national composition, just like in the female version. One additional variation tends to be facial hair: the average GUE-NGL tends to have a full “five o’clock shadow”, the NI representative is more of a grey mustache type, while the average EFDD member has more of a thin goatee king of person. The EPP and ECR on the other hand tend to be the most clean-shaven.

The Data

The photos were downloaded from the European Parliament’s Audiovisual Service for Media. While I’m glad the MEPs have official portraits available for the public, the site could use an upgrade to a more user-friendly way of doing things. The download procedure is cumbersome to say the least, there is no updated folder of all the current MEPs. Therefore I had to download all the photos, crosscheck with a table of current acting MEPs (because some of the original MEPs elected in 2014 quit, in order to take up either positions in their national governments or in the European Commission), see which photos are not needed, which ones are missing, which ones are duplicates and so forth. Two MEPs (Jadwiga Wiśniewska and Jiří Payne) didn’t even have official portraits, so I had to look elsewhere.

The Code

I used the code from learnopencv.com, which I tweaked to my needs. I had just two recurring problems: the fact that above a certain number of photos, I could’t calculate the average due to not enough memory, so I had to split the photos into smaller groups (for example the 475 EPP MEPs were split into 19 groups of 25 photos each, which were averaged, and then those 19 averages were averaged again into one).

My second problem was that sometimes the facial landmark detection part of the code recognized buttons and certain textures as faces, and I realized it pretty late, so I had to redo some of the work.

On a side note, I cannot thank Satya Mallick enough for the clear way he writes his tutorials. They were easy to follow and almost everything worked from the first try (when it didn’t it was usually my fault). Some of the best “how to install and run” articles I’ve ever used.

Made with OpenCV/dlib in Python (Anacond/Spyder as per linked tutorial). Final arrangements in Inkscape.

The History of the European Council

The EU’s Collective Head of State, the European Council held its inaugural meeting on 10 March 1975. In reality, the institution has its roots in the “Summit Meetings” or “Summit Councils” that started with the Rome Summit of 1961. To this date, 182 formal Council meetings have been held (not counting Eurozone Summits, but including Informal ones).

Unlike the European elections, where the makeup of the Parliament changes every 5 years, the composition of the Council changes every time elections in a member state bring about a change in government or president. As such, the Council is in a constant state of flux, especially when it comes to its political leanings. I wanted to track this evolution visually, to get some sense of how the Council evolved.

Click for full size

But the above chart was in fact a preliminary study for a dynamic map (inspired by similar ones featuring the political affiliation of US Governors throughout history).

European Council History

[EDIT] – YouTube LINK to the dynamic map in video format.

Some things I’d wish to highlight:

Interestingly enough, in 1961 the Charles De Gaulle’s party was a member of the “Liberals and Allies” group in the European Parliament (it switched to the conservative “European Democratic Union” in 1965).

“Independents” are PM’s/Presidents who are not party members, while “Non-Inscrits” (“Unaffiliated”) are PM’s who are members of a party that isn’t/wasn’t member of any EP party group, or whose MEP’s sat in multiple groups, essentially denying the party as a whole a political group.

In 2009, Fianna Fail switched from the Conservatives to the Liberals in the EP, even though the Irish PM stayed the same. In such a case, the color of the country changes as well.

There seems to be a consistent shift from the christian-democrats to the liberals in the last five years.

Greens tend to be center-left usually, but the only PM from a Green party was Latvia’s Indulis Emsis whose party is rather conservative, so I chose to position it centrally on the chart.

PS. Happy Europe Day!

Chart and map made in Python. (Updated 24.06.2017)

Great Britain and the European Union of 27

EU27-UK Flow

This latest visualization has its genesis in this reddit thread. I wanted to represent the data therein in a way that would be easier to compare than a print-screen of an Excel table. As time went by, I found more detailed and accurate data, and I started looking at a way in which I could represent the relationship between the UK and the EU27 from the angle of the Four Freedoms :

1. Free Movement of Goods and 2. Services – The main focus of my visualization. Talk about Britain’s future relationship with the EU has often revolved around how free the trade will be and how high the risk of barriers will be. While the flow of goods has been much easier to free than that of services, and will be much easier to keep unrestricted in the post-Brexit world, I treated the two as somewhat two sides of the coin called Trade. A challenge of this infographic was to visualize both the absolute values, and the relative values to each other (imports vs exports, goods vs. services, UK-to-EU27 trade vs. global national trade)

3. Free Movement of People – Easily the most controversial of the Freedoms, at least in the United Kingdom, and a somewhat thorny subject in the early stages of negotiations, the size of Immigrant / Emigrant communities can inform on which countries might have strong incentives to protect their diaspora during negotiations.

4. Free Movement of Capital – By far the one I grasp the least, I limited myself to showing which countries are members of the Eurozone, and which ones still use their national currencies.

Made with Python (svgwrite module) and Inkscape. Data from Eurostat

EU freedom of movement (from East to West)

The Free Movement of People within the European Union has become one of the hot topics surrounding the whole Brexit debate, and the following graph was born out of the desire to explore the relationship between intra-EU work restrictions on new members, and the growth dynamics of the number of immigrants from these new Eastern European states.

The initial idea was to compare the evolution of the number of New EU citizens in the Old EU member states, and especially between the the Big Three – Germany, Britain and France -, who each imposed different levels of restrictions on the 2004 wave of new member states – the wave that gave the world the image of the infamous “Polish plumber”. I wanted to see how much the presence or absence of work-restrictions slowed down immigration from the East.

Here are some of the findings:

  1. The UK is the only country where immigrants from EU-8 (the 2004 wave) grew as fast as those from EU-2 (Romania and Bulgaria). This later wave tended to be bigger in all countries, except the UK (and the 2013 wave, i.e. Croatia, tended to be between the two when it comes to growth)
  2. Work restrictions don’t seem to be the only factor in the rate of growth, but accession is clearly a tipping point when immigration accelerates. The removal of work-restrictions however are noticeable only in some cases (in Austria most clearly)
  3. I was surprised to see much calmer growth post-accession into Germany and Italy, but that is also due to already having larger numbers of immigrants from said countries before those countries joined the EU. The UK and Germany both ended up with 1+ million Central Europeans after 9 years, but they started out out from different base populations (136k vs. 481k)

One immediate problem that prevented me from a broader analysis was the lack of available data in some countries due to different methodologies. France, for example, does not, to my knowledge, publish an estimate on a country by country basis, the EU immigrants being divided solely into “Spain, Portugal, Italy, rest of the EU”, while other countries don’t go far enough into the past to be useful. True to stereotype, the most rigorous seem to be the Germanic nations, which is somewhat fortunate since German-speaking countries and Scandinavian ones are preferred destinations of intra-EU migration. Also, the numbers in Italy after 2011 are based on the census of 2011, but the data before that year, overestimating the number of immigrants, hasn’t been revised, and I had to revise the data myself, so as to not have an odd sudden drop around 2011.


Made in Python w/ Matplotlib (lineplots), LibreCalc (work restriction viz) and Inkscape.

Europarl: Oradea

O cartare a voturilor din Oradea la ultimele europarlamentare. Fiecare diviziune e o secție de vot. Câștigătorii:


Principalii concurenți electorali:PSDUDMRPNL PDLPMP FCDreaptaDiaconuCostea PRMExtra:DensTotalWinner2Harta secțiilor de vot a fost făcută în ArhiCAD, după lista secțiilor de vot conform Ordinul Prefectului nr. 113 din 22.04.2014. Datele au fost sortate printr-un script python și atașate hărții în QGIS. Hărțile finale generate prin QGIS au fost retușate în Inkscape (titlu, legendă, etc.).

Wiki Bihor Bilingv


Inspirat din articolul „O Transilvanie, două lumi” și observații proprii cum că cele două Wikipedii (Ro și Hu) tind să se axeze pe părți diferite ale istoriei, am făcut un experiment. Am scris un progrămel în python care să intre pe articolele localităților din Bihor de pe cele două wikipedii și să identifice anii menționați în articole. Am grupat anii pe decenii, și am făcut graficul de mai sus cu frecvența mențiunilor (mai pe larg: am introdus anii in Excel, am facut un grafic, exportat ca pdf, l-am deschis cu Inkscape si l-am editat ca imagine vectoriala .svg).

Ce se observă:
* lipsa datelor importante înainte de sec. 13
* accent pus de wiki maghiar pe sursele documentare medievale (mai ales cel din 1332-7) și pe recensămintele austriece și austro-ungare
* accent pe istoria dualistă la wiki-maghiar, accent pe istoria post-unire la wiki-român

Freetown: Slobozia

Slobozíe, slobozii, s. f. (Înv.) Sat de coloniști (băștinași sau străini) care aveau pe o perioadă oarecare scutire de bir sau de prestații. – Slobod + suf. -ie.

Primele experimentări cu un program de tip GIS (QGIS). Preluarea datelor de pe Wikipedia s-a făcut cu un script personal în python.

Post-producție în Inkscape.

Varianta-n engleză uploadată și pe Wikimedia Commons.