0
0
Matplotlibdata~10 mins

Basic scatter plot with plt.scatter 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 create a scatter plot with x and y data.

Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [5, 7, 4, 6, 8]
plt.[1](x, y)
plt.show()
Drag options to blanks, or click blank then click option'
Ascatter
Bhist
Cbar
Dplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.plot instead of plt.scatter will create a line plot, not a scatter plot.
Using plt.bar or plt.hist will create bar or histogram plots, which are different.
2fill in blank
medium

Complete the code to add a title to the scatter plot.

Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5, 6]
plt.scatter(x, y)
plt.[1]('My Scatter Plot')
plt.show()
Drag options to blanks, or click blank then click option'
Axlabel
Bylabel
Ctitle
Dlegend
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.xlabel or plt.ylabel adds axis labels, not the plot title.
Using plt.legend adds a legend, not a title.
3fill in blank
hard

Fix the error in the code to correctly plot a scatter plot with red color.

Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [3, 2, 1]
plt.scatter(x, y, color=[1])
plt.show()
Drag options to blanks, or click blank then click option'
Ar
B'red'
Cred
D'r'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing color without quotes causes a NameError.
Using just r without quotes is invalid for color.
4fill in blank
hard

Fill both blanks to create a scatter plot with blue points and label the x-axis as 'Age'.

Matplotlib
import matplotlib.pyplot as plt
x = [20, 25, 30]
y = [5, 7, 9]
plt.scatter(x, y, color=[1])
plt.[2]('Age')
plt.show()
Drag options to blanks, or click blank then click option'
A'blue'
B'Age'
Cxlabel
Dylabel
Attempts:
3 left
💡 Hint
Common Mistakes
Using ylabel instead of xlabel for the x-axis label.
Not putting the color name in quotes.
5fill in blank
hard

Fill all three blanks to create a scatter plot with green points, label the y-axis as 'Height', and add a plot title 'Height vs Age'.

Matplotlib
import matplotlib.pyplot as plt
x = [18, 22, 26]
y = [160, 170, 180]
plt.scatter(x, y, color=[1])
plt.[2]('Height')
plt.[3]('Height vs Age')
plt.show()
Drag options to blanks, or click blank then click option'
A'green'
Bylabel
Ctitle
Dxlabel
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up xlabel and ylabel.
Forgetting quotes around color name.
Using plt.xlabel instead of plt.title for the plot title.