Complete the code to import the matplotlib plotting library.
import [1] as plt
We import matplotlib.pyplot as plt to create plots.
Complete the code to add random jitter to the x-axis positions.
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
Small jitter like 0.1 keeps points close to their categories but avoids overlap.
Fix the error in the scatter plot code to plot jittered points.
plt.scatter([1], y, alpha=0.7) plt.show()
We plot the jittered x positions against y to show spread in categories.
Fill both blanks to create a categorical scatter plot with jitter and labels.
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()
Adding jitter to x spreads points horizontally. plt.xticks uses category names for labels.
Fill all three blanks to create a jittered scatter plot with customized marker size and transparency.
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()
Jitter is added to x for spread. Marker size s=100 makes points bigger. Alpha 0.6 sets transparency.