Bird
0
0
Raspberry Piprogramming~20 mins

Matplotlib for data visualization in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Matplotlib Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Matplotlib code?

Consider the following Python code using Matplotlib. What will be the color of the plotted line?

Raspberry Pi
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6], 'g--')
plt.show()
AA green dashed line
BA blue solid line
CA red dotted line
DA black dash-dot line
Attempts:
2 left
💡 Hint

Look at the format string 'g--' used in the plot function.

data_output
intermediate
2:00remaining
How many bars will be displayed in this bar chart?

Given this code snippet, how many bars will appear in the bar chart?

Raspberry Pi
import matplotlib.pyplot as plt
categories = ['A', 'B', 'C', 'D']
values = [5, 7, 3, 8]
plt.bar(categories, values)
plt.show()
A3 bars
B4 bars
C5 bars
D1 bar
Attempts:
2 left
💡 Hint

Count the number of categories provided.

visualization
advanced
2:00remaining
Which option produces a scatter plot with red circles?

Which code snippet will produce a scatter plot with red circle markers?

A
plt.scatter([1,2,3], [4,5,6], color='blue', marker='x')
plt.show()
B
plt.scatter([1,2,3], [4,5,6], c='red', marker='x')
plt.show()
C
plt.scatter([1,2,3], [4,5,6], c='red', marker='o')
plt.show()
D
plt.scatter([1,2,3], [4,5,6], c='green', marker='s')
plt.show()
Attempts:
2 left
💡 Hint

Check the color and marker shape parameters.

🔧 Debug
advanced
2:00remaining
What error does this Matplotlib code raise?

What error will this code produce when run?

Raspberry Pi
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5])
plt.show()
ANo error, plot displays correctly
BTypeError: unsupported operand type(s)
CSyntaxError: invalid syntax
DValueError: x and y must have same first dimension
Attempts:
2 left
💡 Hint

Check the lengths of x and y lists.

🚀 Application
expert
3:00remaining
Which option produces a line plot with a legend and grid?

Which code snippet correctly creates a line plot with a legend labeled 'Data' and a grid shown?

A
plt.plot([1,2,3], [4,5,6], label='Data')
plt.legend()
plt.grid(True)
plt.show()
B
plt.plot([1,2,3], [4,5,6])
plt.legend('Data')
plt.grid(True)
plt.show()
C
plt.plot([1,2,3], [4,5,6], label='Data')
plt.grid()
plt.show()
D
plt.plot([1,2,3], [4,5,6], label='Data')
plt.legend()
plt.grid(False)
plt.show()
Attempts:
2 left
💡 Hint

Look for correct usage of legend and grid functions.