1

I am follwoing a Datacamp Course on Data Science and I have the following script:

# Import numpy as np
import numpy as np 

# Store pop as a numpy array: np_pop
np_pop = np.array(pop)

# Double np_pop
np_pop*=2

# 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()

It displays the following plot:

Plot

My Question is what does it mean for the s parameter in scatter to be an array ? I understand when it's an int it's the size of the points. However, in the array case, does it map every entry in the array to the size of that specific data Point ?

2
  • 2
    Yes. Exactly like x, or y or color parameters. plt.scatter([1,2,3], [3,1,2], s=[1000, 9000, 111], c=['red', 'green', 'blue']) shows 3 dots at coordinates (1,3), (2,1) and (3,2), second one being 3 times (in radius; 9 times in surface) bigger than the first one, and the last one 3 times smaller, the first one being red, second green and last blue. Doesn't work for everything tho (for example, not for markers. Can't use ['o','o'.'x'] to have the last one a cross Commented Jun 17 at 20:25
  • did you read documentation: matplotlib.pyplot.scatter Commented Jun 18 at 14:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.