Skip to content

Instantly share code, notes, and snippets.

@cavedave
Last active January 14, 2020 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cavedave/afed82654d3826847076cf7ed0b275ec to your computer and use it in GitHub Desktop.
Save cavedave/afed82654d3826847076cf7ed0b275ec to your computer and use it in GitHub Desktop.
Gini of US state populations
x = [1790,1800,1810,1820,1830,1840,1850,1860, 1870,1880,1890,1900,1910,1920,1930,1940,1950, 1960,1970,1980,1990,2000,2010]#year
#with DC y = [0.34,0.40,0.38,0.445,0.435,0.42,0.45,0.43, 0.456,0.43,0.467,0.473,0.455,0.471,0.484,0.481,0.485, 0.509,0.514,0.502,0.510,0.509,0.5097]#gini
y = [0.342,0.366,0.348,0.425,0.415,0.402,0.436,0.416,0.446,0.42,0.467,0.467,0.448,0.466,0.479,0.477,0.481, 0.5058,0.51,0.496,0.50,0.503,0.503]#gini
# Common sizes: (10, 7.5) and (12, 9)
plt.figure(figsize=(12, 9))
# Remove the plot frame lines. They are unnecessary chartjunk.
ax = plt.subplot(111)
ax.spines["top"].set_visible(False)
ax.spines["bottom"].set_visible(False)
ax.spines["right"].set_visible(False)
ax.spines["left"].set_visible(False)
# Limit the range of the plot to only where the data is.
# Avoid unnecessary whitespace.
plt.ylim(0.0, 0.6)
plt.xlim(1790, 2010)
# Make sure your axis ticks are large enough to be easily read.
# You don't want your viewers squinting to read your plot.
#plt.yticks(range(0, 91, 10), [str(x) + "%" for x in range(0, 91, 10)], fontsize=14)
plt.yticks(fontsize=14)
plt.xticks(fontsize=14)
plt.text(1970, 0.52, "Highest in 1970, 0.51" , fontsize=10)
plt.text(1969, 0.51, "•" , fontsize=10)
plt.text(2000, 0.49, "2010 0.503" , fontsize=10)
plt.text(2009, 0.503, "•" , fontsize=10)
plt.text(1793, 0.34, "lowest 1790, 0.34" , fontsize=10)
plt.text(1789.4, 0.338, "•" , fontsize=10)
#interesting points
plt.text(1790, 0.03, "Data: Wikipedia list of U.S. states by historical population"
"\n@iamreddave" , fontsize=10)
# Finally, save the figure as a PNG.
# You can also save it as a PDF, JPEG, etc.
# Just change the file extension in this call.
# bbox_inches="tight" removes all the extra whitespace on the edges of your plot.
plt.title('Historical Inequality in US State Populations', fontsize=22)
plt.xlabel('Year', fontsize=14)
plt.ylabel('Gini Coefficient', fontsize=14)
#plt.subtitle('This is a somewhat long figure title', fontsize=16)
plt.plot(x, y)
plt.savefig("Inequality_Population_US States.png", bbox_inches="tight")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment