0
0
Matplotlibdata~10 mins

Marker size variation in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the marker size to 100 in the scatter plot.

Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5, 6]
plt.scatter(x, y, s=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A100
B1
C10
D50
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'size' instead of 's' parameter.
Setting s to a very small number like 1 which makes markers hard to see.
2fill in blank
medium

Complete the code to create a scatter plot with marker sizes varying by the values in the list 'sizes'.

Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
sizes = [20, 50, 80, 200]
plt.scatter(x, y, s=[1])
plt.show()
Drag options to blanks, or click blank then click option'
Ay
Bx
Csizes
D[10, 20, 30, 40]
Attempts:
3 left
💡 Hint
Common Mistakes
Passing x or y instead of sizes to the 's' parameter.
Passing a list of wrong length to 's'.
3fill in blank
hard

Fix the error in the code to correctly vary marker sizes using the 'sizes' list.

Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5, 6]
sizes = [30, 60, 90]
plt.scatter(x, y, s=[1])
plt.show()
Drag options to blanks, or click blank then click option'
Asizes
Bsize
C[30, 60, 90]
Ds
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'size' instead of 's' parameter.
Passing a string instead of the variable.
4fill in blank
hard

Fill both blanks to create a scatter plot with marker sizes scaled by 10 times the values in 'data_sizes'.

Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [5, 6, 7, 8]
data_sizes = [2, 4, 6, 8]
scaled_sizes = [[1] * size for size in data_sizes]
plt.scatter(x, y, s=[2])
plt.show()
Drag options to blanks, or click blank then click option'
A10
Bdata_sizes
Cscaled_sizes
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Passing data_sizes directly without scaling.
Using wrong variable names.
5fill in blank
hard

Fill all three blanks to create a scatter plot with marker sizes as the square of x values and color as y values.

Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 30, 40]
sizes = [[1] for val in x]
plt.scatter(x, y, s=sizes, c=[2], cmap=[3])
plt.colorbar()
plt.show()
Drag options to blanks, or click blank then click option'
Aval**2
By
C'viridis'
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using x instead of y for colors.
Not squaring x values for sizes.
Using invalid colormap name.