Skip to content

Instantly share code, notes, and snippets.

@64lines
Last active November 6, 2017 16:00
Show Gist options
  • Select an option

  • Save 64lines/c024d1a71401ae0272c686be47c1de38 to your computer and use it in GitHub Desktop.

Select an option

Save 64lines/c024d1a71401ae0272c686be47c1de38 to your computer and use it in GitHub Desktop.
[PYTHON] Plotting with matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
gdp_cap = [10, 11, 12, 14, 18]
life_exp = [11, 30, 13, 41, 12]
# Specify c and alpha inside plt.scatter()
plt.scatter(x = gdp_cap, y = life_exp, s = np.array(pop) * 2, c = col, alpha = 0.8)
# Previous customizations
plt.xscale('log')
plt.xlabel('GDP per Capita [in USD]')
plt.ylabel('Life Expectancy [in years]')
plt.title('World Development in 2007')
plt.xticks([1000,10000,100000], ['1k','10k','100k'])
plt.xticks(rotation=90)
# Additional cool customizations
plt.figure()
sns.countplot(x='education', hue='party', data=df, palette='RdBu')
plt.xticks([0,1], ['No', 'Yes'])
plt.show()
# Show the plot
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment