Bespiel 1

Bespiel 1

Hier ein erstes Beispiel für eine interaktive Visualisierung mit dem Gapminder-Datensatz.

# Und jetzt: Plotly! 
import plotly.express as px

# Plotly Express bringt selbst schon einige Datensätze mit: 
df = px.data.gapminder()

df.head()
country continent year lifeExp pop gdpPercap iso_alpha iso_num
0 Afghanistan Asia 1952 28.801 8425333 779.445314 AFG 4
1 Afghanistan Asia 1957 30.332 9240934 820.853030 AFG 4
2 Afghanistan Asia 1962 31.997 10267083 853.100710 AFG 4
3 Afghanistan Asia 1967 34.020 11537966 836.197138 AFG 4
4 Afghanistan Asia 1972 36.088 13079460 739.981106 AFG 4

Jetzt machen wir ganz einfach einen fancy Scatterplot mit Bubbles

fig = px.scatter(df.query('year==2007'), x='gdpPercap', y='lifeExp', 
                 size='pop', color='continent', 
                 hover_name='country', log_x=True, size_max=60, 
                 title='Life expectancy by GDP per capita for each country in 2007', 
                 labels=dict(gdpPercap="GDP per capita", lifeExp='Life expectancy', continent='Continent'))
fig.show()