0
0
Matplotlibdata~10 mins

Line styles (solid, dashed, dotted) 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 solid line using matplotlib.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6], linestyle=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A"--"
B"-"
C":"
D"-."
Attempts:
3 left
💡 Hint
Common Mistakes
Using "--" which creates a dashed line instead of solid.
Using ":" which creates a dotted line.
2fill in blank
medium

Complete the code to plot a dashed line using matplotlib.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6], linestyle=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A"-"
B":"
C"--"
D"-."
Attempts:
3 left
💡 Hint
Common Mistakes
Using "-" which creates a solid line instead of dashed.
Using ":" which creates a dotted line.
3fill in blank
hard

Fix the error in the code to plot a dotted line using matplotlib.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6], linestyle=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A"-."
B"-"
C"--"
D":"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "-" or "--" which create solid or dashed lines instead of dotted.
Repeating the same option twice.
4fill in blank
hard

Fill both blanks to create a plot with a dashed line and label it 'Dashed'.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6], linestyle=[1], label=[2])
plt.legend()
plt.show()
Drag options to blanks, or click blank then click option'
A"--"
B"Dotted"
C"Dashed"
D"-"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong linestyle for dashed lines.
Labeling the line incorrectly.
5fill in blank
hard

Fill all three blanks to create a plot with a dotted line, label it 'Dotted', and set the line width to 2.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6], linestyle=[1], label=[2], linewidth=[3])
plt.legend()
plt.show()
Drag options to blanks, or click blank then click option'
A"--"
B"Dotted"
C2
D":"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong linestyle for dotted lines.
Forgetting to set the linewidth correctly.