Plot Scatter Graph with Python with Label and Title
import numpy as np
import matplotlib.pyplot as plt
gdp =[84580,76398,68402,65521,64684,61373]
life_exp =[80,82,77,83,75,82]
population =[300000,500000,100000,200000,5000000,600000]
Age vs GDP Correlate to Pouplation Size Represent by the Circle Area As the Population Figure is too Large , assign it a power of 0.5 too scale down the numbers
pop = np.array(population)
pop = np.array(pop)**0.5
plt.scatter(gdp, life_exp, s =pop)
<matplotlib.collections.PathCollection at 0x24820344280>
xlab = 'GDP per Capita [in USD]'
ylab = 'Life Expectancy [in years]'
title = 'World Development'
Assign a cell a title x, y Label Log the x axis Scale to make it smaller Create 3 x series break point with xticks ( 1K , 10K, 100K)
Assigning Color to population List [300000,500000,100000,200000,5000000,600000] color equals to ['green','blue','red','black','grey','orange'] Assigning Alpha 1 is opaque 0 is Transparent Add some Horizontal Grid Line Add a mock Text
plt.xlabel(xlab)
plt.ylabel(ylab)
plt.title(title)
plt.scatter(x = gdp, y = life_exp, s = pop, c=['green','blue','red','black','grey','orange'],alpha=1)
plt.xscale('log')
plt.grid(True)
plt.xticks([1000,10000,100000], ['1k','10k','100k'])
plt.text(6000, 80, 'Add Text')
Text(6000, 80, 'Add Text')