What if you have three variables : Life Expectancy, GDP and Population and want to see how they behave with each other.

So the blue blobs are how large the population is in some countries witch a certain overlap between life-expectancy and GDP. The bigger the blob – the bigger the life expectancy. How we achieve this is by introducing a numpy array of the third variable into the scatter chart.

Here the population (pop) is the 3rd variable:

# Import numpy as np

import numpy as np

# Store pop as a numpy array: np_pop

np_pop = np.array(pop)

# Update: set s argument to np_pop

plt.scatter(gdp_cap, life_exp, **s = np_pop)**

# 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’])

# Display the plot

plt.show()

### Like this:

Like Loading...

## Leave a Reply