DP-500 · Question #53
DP-500 Question #53: Real Exam Question with Answer & Explanation
This question tests your ability to read and interpret matplotlib scatter plot code in an Azure Synapse notebook, including understanding data series properties (marker style, color) and detecting array length mismatches that cause runtime errors.
Question
You have the following code in an Azure Synapse notebook. ```python import matplotlib.pyplot as plt x1 = [2, 3, 4] y1 = [5, 9, 5] x2 = [1, 2, 3, 4, 5] y2 = [2, 3, 4] y3 = [6, 8, 7] plt.scatter(x1, y1) plt.scatter(x2, y2, marker= 'v', color= 'r') plt.scatter(x2, y3, marker= '^', color= 'm') plt.title('Scatter Plot') plt.show() ``` Use the drop-down menus to select the answer choice that completes each statement based on the information presented in the code. NOTE: Each correct selection is worth one point.
Explanation
This question tests your ability to read and interpret matplotlib scatter plot code in an Azure Synapse notebook, including understanding data series properties (marker style, color) and detecting array length mismatches that cause runtime errors.
Approach. The code attempts to plot three scatter series on one chart. The first call plt.scatter(x1, y1) is valid: x1 and y1 both have 3 elements, so it renders with default markers (circles) and the default blue color. The second and third calls - plt.scatter(x2, y2) and plt.scatter(x2, y3) - are invalid: x2 has 5 elements while y2 and y3 each have only 3 elements. Matplotlib's scatter() requires x and y to be the same size and raises a ValueError ('x and y must be the same size') at runtime. Therefore the plot title 'Scatter Plot' is never displayed, and only the valid series' properties are relevant: marker 'v' (downward triangle) in red ('r') for series 2, and marker '^' (upward triangle) in magenta ('m') for series 3, had they been valid.
Concept tested. Understanding matplotlib.pyplot.scatter() syntax in Azure Synapse notebooks - specifically: (1) how multiple series are layered on one figure using successive plt.scatter() calls, (2) the meaning of marker and color keyword arguments, and (3) the requirement that x and y arrays passed to scatter() must have equal length, with mismatches causing a ValueError that aborts execution.
Reference. matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.scatter.html - see 'Parameters: x, y: array-like, shape (n,)'
Topics
Community Discussion
No community discussion yet for this question.