Visualizing data with Plotly
Set up
!pip install statsmodels==0.13.2
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
import plotly.graph_objects as go
import statsmodels.api as sm
import statsmodels.formula.api as smf
Import data
df = pd.read_csv('/work/data/dat.csv')
df
df2014 = df.query("year == 2014")
df2014
Population distribution and levels of GDP per capita
px.sunburst(df2014, color= 'log_GDPpc',
values='pop', path=['region', 'country'],
hover_name='country',
labels= dict(
labels = 'country',
pop = 'population',
parent = 'id'
))
Spatial distribution of GDP per capita
fig = px.choropleth(df,
locations = 'isocode',
color = 'log_GDPpc',
hover_name = 'country',
animation_frame = 'year',
range_color = [4, 11]
)
fig.show()
Population distribution and levels of GDP per capita
fig = px.treemap(df2014,
color="log_GDPpc",
values="pop",
path=["region","country"],
hover_name="country",
height=500)
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
fig.show()