Skip to content

Commit 2f43f26

Browse files
committed
tweaks from review of preview
1 parent 50f75e3 commit 2f43f26

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

lectures/inequality.md

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -698,27 +698,12 @@ ginis.head(n=5)
698698
699699
Let's plot the Gini coefficients for net wealth, labor income and total income.
700700
701-
Looking at each data series we see an outlier in Gini coefficient computed for 1965 for `labour income`.
702-
703-
We will smooth our data and take an average of the data either side of it for the time being.
704-
705-
```{code-cell} ipython3
706-
ginis["l_income"][1965] = (ginis["l_income"][1962] + ginis["l_income"][1968]) / 2
707-
ax = ginis["l_income"].plot()
708-
ax.set_ylabel("Gini coefficient")
709-
plt.show()
710-
```
711-
712-
Now we can focus on US net wealth
713-
714701
```{code-cell} ipython3
715702
---
716703
mystnb:
717704
figure:
718705
caption: Gini coefficients of US net wealth
719706
name: gini_wealth_us
720-
image:
721-
alt: gini_wealth_us
722707
---
723708
fig, ax = plt.subplots()
724709
ax.plot(years, ginis["n_wealth"], marker='o')
@@ -727,16 +712,22 @@ ax.set_ylabel("Gini coefficient")
727712
plt.show()
728713
```
729714
730-
and look at US income for both labour and a total income (excl. capital gains)
715+
Looking at each data series we see an outlier in Gini coefficient computed for 1965 for `labour income`.
716+
717+
We will smooth our data and take an average of the data either side of it for the time being.
718+
719+
```{code-cell} ipython3
720+
ginis["l_income"][1965] = (ginis["l_income"][1962] + ginis["l_income"][1968]) / 2
721+
```
722+
723+
Now looking at US income for both labour and a total income.
731724
732725
```{code-cell} ipython3
733726
---
734727
mystnb:
735728
figure:
736729
caption: Gini coefficients of US income
737730
name: gini_income_us
738-
image:
739-
alt: gini_income_us
740731
---
741732
fig, ax = plt.subplots()
742733
ax.plot(years, ginis["l_income"], marker='o', label="labor income")
@@ -750,6 +741,12 @@ plt.show()
750741
Now we can compare net wealth and labour income.
751742
752743
```{code-cell} ipython3
744+
---
745+
mystnb:
746+
figure:
747+
caption: Gini coefficients of US net wealth and labour income
748+
name: gini_wealth_us
749+
---
753750
fig, ax = plt.subplots()
754751
ax.plot(years, ginis["n_wealth"], marker='o', label="net wealth")
755752
ax.plot(years, ginis["l_income"], marker='o', label="labour income")
@@ -791,11 +788,14 @@ data[['NOR']].dropna().head(n=5)
791788
792789
The data for Norway in this dataset goes back to 1979 but there are gaps in the time series and matplotlib is not showing those data points.
793790
794-
We can use `dataframe.ffill()` to copy and bring forward the last known value in a series to fill in these gaps
791+
We can use the `.ffill()` method to copy and bring forward the last known value in a series to fill in these gaps
795792
796793
```{code-cell} ipython3
797794
data['NOR'] = data['NOR'].ffill()
798-
data[['USA','GBR', 'NOR']].plot(ylabel='gini coefficient')
795+
ax = data[['USA','GBR', 'NOR']].plot()
796+
ax.set_xlabel('year')
797+
ax.set_ylabel('Gini coefficient')
798+
plt.show()
799799
```
800800
801801
From this plot we can observe that the USA has a higher Gini coefficient (i.e. higher income inequality) when compared to the UK and Norway.
@@ -854,6 +854,7 @@ labels = [1979, 1986, 1991, 1995, 2000, 2020, 2021, 2022] + list(range(min_year,
854854
plot_data.year = plot_data.year.map(lambda x: x if x in labels else None)
855855
```
856856
857+
(fig:plotly-gini-gdppc-years)=
857858
```{code-cell} ipython3
858859
fig = px.line(plot_data,
859860
x = "gini",
@@ -867,6 +868,10 @@ fig.update_traces(textposition="bottom right")
867868
fig.show()
868869
```
869870
871+
```{only} latex
872+
This figure is built using `plotly` and is {ref}` available on the website <fig:plotly-gini-gdppc-years>`
873+
```
874+
870875
This plot shows that all three western economies gdp per capita has grown over time with some fluctuations
871876
in the Gini coefficient. However the appears to be significant structural differences between Norway and the USA.
872877

0 commit comments

Comments
 (0)