In Figure Friday week 44 we’ll take a look at German (Federal) elections from 1953 to 2021. The data includes number of eligible voters, valid votes, invalid votes, and share of votes per political party.
If you’d like to explore data sets on local and state elections in Germany, you can find them on the GERDA data files page.
Things to consider:
- can you improve the sample figure built?
- would a different figure tell the data story better?
- can you create a Dash app instead?
Sample figure:
Code for sample figure:
import pandas as pd
import plotly.express as px
df = pd.read_csv("https://raw.githubusercontent.com/plotly/Figure-Friday/refs/heads/main/2024/week-44/federal_cty_unharm.csv")
df_by_year = df.groupby('year')[['invalid_votes', 'valid_votes', 'eligible_voters', 'number_voters']].sum().reset_index()
fig = px.line(df_by_year, x="year", y=["number_voters", "eligible_voters"], text="year")
fig.update_traces(textposition="bottom right")
fig.add_vline(x=1989, line_width=3, line_dash="dash", line_color="green", annotation_text="The Berlin Wall fell in 1989.")
fig.show()
Participation Instructions:
- Create - use the weekly data set to build your own Plotly visualization or Dash app. Or, enhance the sample figure provided in this post, using Plotly or Dash.
- Submit - post your creation to LinkedIn or Twitter with the hashtags
#FigureFriday
and#plotly
by midnight Thursday, your time zone. Please also submit your visualization as a new post in this thread. - Celebrate - join the Figure Friday sessions to showcase your creation and receive feedback from the community.
If you prefer to collaborate with others on Discord, join the Plotly Discord channel.
Data Source:
Thank you to GERDA for the data. Please cite the accompanying paper when using this dataset:
Heddesheimer, Vincent, Hanno Hilbig, Florian Sichart, & Andreas Wiedemann. 2024. “German Election Database”.
@article{Heddesheimer2024GermanElections,
author = {Heddesheimer Vincent, and Hanno Hilbig, and Florian Sichart and Andreas Wiedemann},
title = {German Election Database},
year = {2024},
url = {https://osf.io/preprints/socarxiv/q28ex},
doi = {https://doi.org/10.31235/osf.io/q28ex}
}