Complete the code to plot a scatter plot using matplotlib.
import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [2, 3, 5, 7, 11] plt.[1](x, y) plt.show()
The scatter function creates a scatter plot, which is used to show points on a graph.
Complete the code to calculate the slope and intercept of a linear trend line using numpy.
import numpy as np x = np.array([1, 2, 3, 4, 5]) y = np.array([2, 3, 5, 7, 11]) slope, intercept = np.polyfit(x, y, [1])
The degree of the polynomial for a linear fit is 1.
Fix the error in the code to plot the trend line on the scatter plot.
import matplotlib.pyplot as plt import numpy as np x = np.array([1, 2, 3, 4, 5]) y = np.array([2, 3, 5, 7, 11]) slope, intercept = np.polyfit(x, y, 1) plt.scatter(x, y) plt.plot(x, slope * [1] + intercept, color='red') plt.show()
The trend line is calculated as slope times x plus intercept, so x must be used in the plot.
Fill both blanks to create a dictionary of squared values for numbers greater than 3.
numbers = [1, 2, 3, 4, 5] squares = {num: num[1]2 for num in numbers if num [2] 3}
Use ** for exponentiation and > to filter numbers greater than 3.
Fill all three blanks to create a dictionary of uppercase keys and values greater than 0.
data = {'a': 1, 'b': -2, 'c': 3}
result = [1]: [2] for [3], [2] in data.items() if [2] > 0Keys are converted to uppercase with k.upper(), values are v, and the loop variable is k and v unpacked from data.items().