0
0
Matplotlibdata~10 mins

Line colors and width 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 set the line color to red.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6], color=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A'blue'
B'yellow'
C'green'
D'red'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the color name.
Using an invalid color name.
2fill in blank
medium

Complete the code to set the line width to 3.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6], linewidth=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A3
B1
C5
D0.5
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number.
Choosing a very small number that makes the line hard to see.
3fill in blank
hard

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

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6], color=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A'blue'
BBLUE
C"blue"
Dblue
Attempts:
3 left
💡 Hint
Common Mistakes
Using the color name without quotes.
Using uppercase letters without quotes.
4fill in blank
hard

Fill both blanks to set the line color to green and width to 2.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6], color=[1], linewidth=[2])
plt.show()
Drag options to blanks, or click blank then click option'
A'green'
B1
C2
D'red'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up color and linewidth values.
Using numbers for color or strings for linewidth.
5fill in blank
hard

Fill all three blanks to create a blue line with width 4 and label it 'My Line'.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6], color=[1], linewidth=[2], label=[3])
plt.legend()
plt.show()
Drag options to blanks, or click blank then click option'
A'blue'
B4
C'My Line'
D'red'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the label.
Using a string for linewidth or number for color.