Look at the following code that plots two lines. Which option shows the correct colors used in the plot?
import matplotlib.pyplot as plt x = [1, 2, 3, 4] y1 = [1, 4, 9, 16] y2 = [2, 3, 5, 7] plt.plot(x, y1, color='red', label='Squares') plt.plot(x, y2, color='blue', label='Primes') plt.legend() plt.show()
Check the color argument in each plt.plot call.
The first line uses color='red' and the second line uses color='blue'. So the first line is red and the second is blue.
What will be the line style of the plot created by this code?
import matplotlib.pyplot as plt x = [0, 1, 2, 3] y = [0, 1, 4, 9] plt.plot(x, y, linestyle='--') plt.show()
Look at the linestyle argument.
The linestyle='--' means the line will be dashed.
What error does this code raise and why?
import matplotlib.pyplot as plt x = [1, 2, 3] y = [4, 5, 6] plt.plot(x, y, color=blue) plt.show()
Check how color names should be passed as strings.
The color name must be a string. Without quotes, Python looks for a variable named blue which is not defined, causing a NameError.
You want to plot data points as red circles and connect them with a dotted line. Which code achieves this?
Use marker for points and linestyle for line style. Color applies to both.
Option D uses marker='o' for circle markers, color='red' for red color on both markers and line, and linestyle=':' for dotted line.
Which of the following best explains why customizing plots is important in data science?
Think about how changing colors, labels, and styles can help tell a story with data.
Customization helps emphasize key points, makes plots easier to read, and supports better communication of insights.