0
0
Matplotlibdata~10 mins

Basic plt.plot usage 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 plot a simple line graph of y values.

Matplotlib
import matplotlib.pyplot as plt

y = [1, 3, 2, 4]
plt.[1](y)
plt.show()
Drag options to blanks, or click blank then click option'
Ascatter
Bbar
Cplot
Dhist
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.scatter instead of plt.plot for line graphs.
Using plt.bar which creates bar charts, not line plots.
2fill in blank
medium

Complete the code to plot x and y values as a line graph.

Matplotlib
import matplotlib.pyplot as plt

x = [0, 1, 2, 3]
y = [1, 3, 2, 4]
plt.plot([1], y)
plt.show()
Drag options to blanks, or click blank then click option'
Ay
B[0, 0, 0]
C[1, 2, 3]
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Passing y twice instead of x and y.
Passing a list of zeros which will plot all points on the y-axis.
3fill in blank
hard

Fix the error in the code to plot x and y values with a red dashed line.

Matplotlib
import matplotlib.pyplot as plt

x = [0, 1, 2, 3]
y = [1, 3, 2, 4]
plt.plot(x, y, [1])
plt.show()
Drag options to blanks, or click blank then click option'
A'r--'
B'blue'
C'green'
D'--r'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'blue' or 'green' which are color names but not combined with line style.
Reversing the order as '--r' which is invalid.
4fill in blank
hard

Fill both blanks to create a plot with x and y values and label the x-axis.

Matplotlib
import matplotlib.pyplot as plt

x = [1, 2, 3]
y = [4, 5, 6]
plt.[1](x, y)
plt.[2]('Time (s)')
plt.show()
Drag options to blanks, or click blank then click option'
Aplot
Bxlabel
Cylabel
Dtitle
Attempts:
3 left
💡 Hint
Common Mistakes
Using ylabel instead of xlabel for the x-axis label.
Forgetting to plot the data before labeling.
5fill in blank
hard

Fill all three blanks to create a plot with x and y, add a title, and label the y-axis.

Matplotlib
import matplotlib.pyplot as plt

x = [0, 1, 2]
y = [3, 1, 4]
plt.[1](x, y)
plt.[2]('Sample Plot')
plt.[3]('Value')
plt.show()
Drag options to blanks, or click blank then click option'
Aplot
Btitle
Cylabel
Dxlabel
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up xlabel and ylabel.
Forgetting to add the title or y-axis label.