0
0
Matplotlibdata~10 mins

Statistical plot enhancements in Matplotlib - Interactive Code Practice

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

Complete the code to add a title to the plot.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.[1]('My Plot')
plt.show()
Drag options to blanks, or click blank then click option'
Alegend
Btitle
Cylabel
Dxlabel
Attempts:
3 left
💡 Hint
Common Mistakes
Using xlabel or ylabel instead of title.
Trying to add a legend without labels.
2fill in blank
medium

Complete the code to add grid lines to the plot.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.[1](True)
plt.show()
Drag options to blanks, or click blank then click option'
Agrid
Baxis
Clegend
Dscatter
Attempts:
3 left
💡 Hint
Common Mistakes
Using legend instead of grid.
Trying to use axis to add grid lines.
3fill in blank
hard

Fix the error in the code to set x-axis label correctly.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.xlabel[1]('Time (s)')
plt.show()
Drag options to blanks, or click blank then click option'
A( )
B[ ]
C{ }
D< >
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or curly braces instead of parentheses.
Forgetting parentheses entirely.
4fill in blank
hard

Fill both blanks to create a scatter plot with red color and circle markers.

Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5, 6]
plt.scatter(x, y, color=[1], marker=[2])
plt.show()
Drag options to blanks, or click blank then click option'
A'red'
B'blue'
C'o'
D'x'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong quotes or missing quotes around color.
Using wrong marker symbols.
5fill in blank
hard

Fill all three blanks to create a histogram with 10 bins, green color, and alpha transparency 0.5.

Matplotlib
import matplotlib.pyplot as plt
data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
plt.hist(data, bins=[1], color=[2], alpha=[3])
plt.show()
Drag options to blanks, or click blank then click option'
A5
B'green'
C0.5
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using string instead of number for bins.
Forgetting quotes around color.
Using alpha values outside 0 to 1 range.