How Europe is generating electricity — Analysis with Plotly

One close look at the electricity generation in Europe, using Plotly library to generate interactive charts.

Afonso Lugo
Analytics Vidhya
5 min readApr 3, 2020

--

Renewable power accounted for 70% of net additions to global power generating capacity in 2017, but global energy-related carbon dioxide emissions rose 1.4% in 2017, according to the report “ Renewables Global Status Report (GSR)” of REN 21 Community.

The track of the electricity generation is one important way to follow the decabornisation of the power sector in order to see how much of each energy source is contributing to the electricity supply. There are several sources for this type of data and today we will work with the International Renewable Agency — IRENA. You can go to the website https://www.irena.org/ and check all the information and data provided about energy in general.

The following graph shows the electricity generation in Europe from 1990 to 2017. It is possible to note the decreasing of coal and oil, the almost constant generation from hydro and nuclear and the increasing of the renewable sources. One problem in this graph is difference in the proportion of some sources, making them almost invisible in this representation.

Electricity generation in Europe. Data source: IRENA.

When you are making a presentation is important to have tools to show your research in the proper way, according to what story you are telling. In the previous graph (made with Matplolib), if you want to focus in the renewable sources, this is not the best way to show your data.

Check this publication about wind energy in Europe and Matplotlib.

The following video shows the same data presented in an interactive way with Plotly. With this tool we can zoom the plot area, see the values on the screen, take out some sources, add them back and even save an image of the modified view.

There are several ways to make this visualization and I will show you one of them that is easy to understand. We will use Pandas to read the CSV file, Numpy to manipulate the data and Plotly to create the visualization. So the first step is to import the libraries which you will use and than call the class ‘read_csv’ from Pandas to load the data.

It is always useful to check how the data is loaded using ‘df.head()’ to see the first 05 rows of the data frame.

Some values were loaded as NaN (not a number) and this is not good for our analysis. We can use df.fillna(0) to replace these NaN values by zero, as shown in the following image.

Now we use the class ‘asarray’ from Numpy to manipulate the data from Pandas data frame.

Now we can start the graph by creating a figure and adding the plots of each array created before. The parameters “fill = ‘tonexty’” is used to create one area on top of each, “stackgroup = ‘one’” makes one group for all the sources and “mode = ‘none’” remove the lines of the areas.

Finally we can customize the figure of the plot, adding a title, labels to y and x, legend and everything that we think is necessary.

Python is maybe the best language for data analysis because it is easy to understand and it provides a huge variety of tools to manipulate our data and to create many types of visualization which can be used for internal analysis and in final reports or live presentations.

Thanks for reading it!

Twitter @afonso_lugo

LinkedIn Afonso Lugo

--

--

Afonso Lugo
Analytics Vidhya

Energy Engineer, researcher at LUT university and co-founder of ePowerBay platform.