0
0
Matplotlibdata~10 mins

Why color matters in visualization in Matplotlib - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the matplotlib library for plotting.

Matplotlib
import [1] as plt
Drag options to blanks, or click blank then click option'
Apandas
Bseaborn
Cmatplotlib.pyplot
Dnumpy
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the whole matplotlib instead of pyplot.
Using unrelated libraries like pandas or numpy.
2fill in blank
medium

Complete the code to create a simple line plot with x and y data.

Matplotlib
plt.plot([1], [1, 4, 9, 16])
plt.show()
Drag options to blanks, or click blank then click option'
A[1, 2, 3, 4]
B['a', 'b', 'c', 'd']
C[10, 20, 30, 40]
D[0, 0, 0, 0]
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of numbers for x values.
Using lists of different length than y values.
3fill in blank
hard

Fix the error in the code to set the color of the line to blue.

Matplotlib
plt.plot([1, 2, 3, 4], [1, 4, 9, 16], color=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A'yellow'
B'red'
C'green'
D'blue'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the color name.
Using a color name that is not recognized.
4fill in blank
hard

Fill both blanks to create a scatter plot with red points and label the x-axis.

Matplotlib
plt.scatter([1, 2, 3], [4, 5, 6], color=[1])
plt.xlabel([2])
plt.show()
Drag options to blanks, or click blank then click option'
A'red'
B'blue'
C'X Axis'
D'Y Axis'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up x-axis and y-axis labels.
Using color names without quotes.
5fill in blank
hard

Fill all three blanks to create a bar chart with green bars, set the title, and label the y-axis.

Matplotlib
plt.bar(['A', 'B', 'C'], [5, 7, 3], color=[1])
plt.title([2])
plt.ylabel([3])
plt.show()
Drag options to blanks, or click blank then click option'
A'green'
B'Sales Data'
C'Quantity'
D'blue'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong color names or missing quotes.
Confusing title and axis labels.