72 lines
2.2 KiB
Text
72 lines
2.2 KiB
Text
|
---
|
||
|
format:
|
||
|
html:
|
||
|
code-fold: true
|
||
|
standalone: true
|
||
|
fig-cap-location: top
|
||
|
---
|
||
|
|
||
|
```{python}
|
||
|
#| echo: false
|
||
|
import matplotlib.pyplot as plt
|
||
|
def prepare_plot_colors():
|
||
|
# "Tableau 20" colors as RGB.
|
||
|
colors = [(31, 119, 180), (174, 199, 232), (255, 127, 14), (255, 187, 120),
|
||
|
(44, 160, 44), (152, 223, 138), (214, 39, 40), (255, 152, 150),
|
||
|
(148, 103, 189), (197, 176, 213), (140, 86, 75), (196, 156, 148),
|
||
|
(227, 119, 194), (247, 182, 210), (127, 127, 127), (199, 199, 199),
|
||
|
(188, 189, 34), (219, 219, 141), (23, 190, 207), (158, 218, 229)]
|
||
|
|
||
|
# Scale RGB values to the [0, 1] range for matplotlib
|
||
|
for i in range(len(colors)):
|
||
|
r, g, b = colors[i]
|
||
|
colors[i] = (r / 255., g / 255., b / 255.)
|
||
|
return colors
|
||
|
|
||
|
colors=prepare_plot_colors()
|
||
|
```
|
||
|
|
||
|
```{python}
|
||
|
#| echo: false
|
||
|
import openpyxl
|
||
|
import pandas as pd
|
||
|
|
||
|
df = pd.read_csv('data/cleaned/UNU-WIDER-WIID/WIID-30JUN2022_cty-select.csv', index_col="id", parse_dates=True)
|
||
|
```
|
||
|
|
||
|
```{python}
|
||
|
#| echo: false
|
||
|
df = df.loc[df['year'] > 2000]
|
||
|
ben = df.loc[df['c3'] == "BEN"]
|
||
|
dji = df.loc[df['c3'] == "DJI"]
|
||
|
uga = df.loc[df['c3'] == "UGA"]
|
||
|
vnm = df.loc[df['c3'] == "VNM"]
|
||
|
```
|
||
|
|
||
|
```{python}
|
||
|
# Set up the data extraction and figure drawing functions
|
||
|
import plotly.express as px
|
||
|
import plotly.io as pio
|
||
|
|
||
|
def gini_plot(country_df):
|
||
|
if svg_render:
|
||
|
pio.renderers.default = "png"
|
||
|
|
||
|
fig = px.line(country_df, x="year", y="gini", markers=True, labels={"year": "Year", "gini": "Gini coefficient"}, template="seaborn", range_y=[30,60])
|
||
|
fig.update_traces(marker_size=10)
|
||
|
fig.show()
|
||
|
|
||
|
def plot_consumption_gini_percapita(country_df):
|
||
|
gni_cnsmpt = country_df[country_df['resource'].str.contains("Consumption")]
|
||
|
gni_cnsmpt_percapita = gni_cnsmpt[gni_cnsmpt['scale'].str.contains("Per capita")]
|
||
|
gini_plot(gni_cnsmpt_percapita)
|
||
|
|
||
|
def plot_consumption_gini_percapita_ruralurban(country_df):
|
||
|
gni_cnsmpt = country_df[country_df['resource'].str.contains("Consumption")]
|
||
|
gni_cnsmpt = gni_cnsmpt[gni_cnsmpt['scale'].str.contains("Per capita")]
|
||
|
gni_cnsmpt = gni_cnsmpt[gni_cnsmpt['source'].str.contains("World Bank")]
|
||
|
gni_cnsmpt = gni_cnsmpt[gni_cnsmpt['areacovr'].str.contains("All")]
|
||
|
gini_plot(gni_cnsmpt)
|
||
|
```
|
||
|
|