0
0
Matplotlibdata~10 mins

Categorical scatter with jitter 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 import the matplotlib plotting library.

Matplotlib
import [1] as plt
Drag options to blanks, or click blank then click option'
Amatplotlib.pyplot
Bseaborn
Cpandas
Dnumpy
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong library like seaborn or numpy.
Forgetting to import pyplot specifically.
2fill in blank
medium

Complete the code to add random jitter to the x-axis positions.

Matplotlib
import numpy as np
x = np.array([1, 2, 3, 4, 5])
jitter = np.random.uniform(-[1], [1], size=x.size)
x_jittered = x + jitter
Drag options to blanks, or click blank then click option'
A0.5
B1.0
C0.1
D2.0
Attempts:
3 left
💡 Hint
Common Mistakes
Using too large jitter which scatters points too far.
Using zero jitter which causes overlapping points.
3fill in blank
hard

Fix the error in the scatter plot code to plot jittered points.

Matplotlib
plt.scatter([1], y, alpha=0.7)
plt.show()
Drag options to blanks, or click blank then click option'
Ax
Bx_jittered
Cy_jittered
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Plotting original x without jitter causes overlapping points.
Using y for x-axis values causes wrong plot.
4fill in blank
hard

Fill both blanks to create a categorical scatter plot with jitter and labels.

Matplotlib
categories = ['A', 'B', 'C', 'D']
values = [5, 7, 6, 8]
x = np.arange(len(categories))
jitter = np.random.uniform(-0.1, 0.1, size=len(x))
plt.scatter(x + [1], values, color='blue')
plt.xticks(x, [2])
plt.show()
Drag options to blanks, or click blank then click option'
Ajitter
Bcategories
Cvalues
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using values instead of categories for x-axis labels.
Not adding jitter causing overlapping points.
5fill in blank
hard

Fill all three blanks to create a jittered scatter plot with customized marker size and transparency.

Matplotlib
x = np.array([1, 2, 3, 4])
y = np.array([10, 15, 13, 17])
jitter = np.random.uniform(-0.15, 0.15, size=x.size)
plt.scatter(x + [1], y, s=[2], alpha=[3], color='green')
plt.show()
Drag options to blanks, or click blank then click option'
Ajitter
B100
C0.6
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using original x without jitter.
Setting alpha to 1 (opaque) or too low (invisible).
Using too small marker size.