Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The 's' parameter in plt.scatter controls the marker size. Setting s=100 makes the markers larger.
2fill in blank
mediumComplete 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'
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'.
✗ Incorrect
Passing the list 'sizes' to the 's' parameter sets marker sizes individually for each point.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'size' instead of 's' parameter.
Passing a string instead of the variable.
✗ Incorrect
The 's' parameter must be assigned the variable 'sizes' to vary marker sizes correctly.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing data_sizes directly without scaling.
Using wrong variable names.
✗ Incorrect
Multiply each size by 10 to scale, then pass the scaled_sizes list to 's' for marker sizes.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using x instead of y for colors.
Not squaring x values for sizes.
Using invalid colormap name.
✗ Incorrect
Marker sizes are squares of x values, colors are y values, and 'viridis' colormap is used.