import matplotlib.pyplot as plt
year =[list]
pop = [list]
plt.plot(year,pop)
#plt.scatter(gdp_cap,life_exp)
#plt.xscale('log')
#以log的形式表现
#information show on the plot
plt.xlabel('year')
plt.ylabel('polulation')
plt.title('wolrd')
plt.yticks([0,2,4,6,8,10],['0','2B','4B','6B','8B','10B'])
#the ticks corresponding to the numbers 0, 2 and 4 will be replaced by '0', '2B' and '4B', respectively.
plt.show()
# Scatter plot
#Wouldn't it be nice if the size of the dots corresponds to the population,
#pop list contains population numbers for each country expressed in millions.
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'])
# Additional customizations
plt.text(1550, 71, 'India')
plt.text(5700, 80, 'China')
# Add grid() call
plt.grid(True)
# Show the plot
plt.show()
add plt.grid(True) after the plt.text() calls so that gridlines are drawn on the plot
Addc = col
to the arguments of theplt.scatter()
function.
- Change the opacity of the bubbles by setting the
alpha
argument to0.8
insideplt.scatter()
Alpha can be set from zero to one, where zero is totally transparent, and one is not at all transparent.