0
0
Matplotlibdata~10 mins

Axis limits (xlim, ylim) 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 x-axis limits from 0 to 10.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.[1](0, 10)
plt.show()
Drag options to blanks, or click blank then click option'
Aylim
Bxlim
Caxis
Dset_xlim
Attempts:
3 left
💡 Hint
Common Mistakes
Using ylim instead of xlim.
Using set_xlim without plt prefix.
Using axis which sets both axes limits.
2fill in blank
medium

Complete the code to set the y-axis limits from -5 to 5.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.[1](-5, 5)
plt.show()
Drag options to blanks, or click blank then click option'
Axlim
Bset_ylim
Caxis
Dylim
Attempts:
3 left
💡 Hint
Common Mistakes
Using xlim instead of ylim.
Using set_ylim without plt prefix.
Using axis which sets both axes limits.
3fill in blank
hard

Fix the error in the code to set both x and y axis limits correctly.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.axis([1])
plt.show()
Drag options to blanks, or click blank then click option'
A[0, 10, 5, -5]
B(0, 10, -5, 5)
C[0, 10, -5, 5]
D(10, 0, -5, 5)
Attempts:
3 left
💡 Hint
Common Mistakes
Using tuple instead of list.
Swapping ymin and ymax values.
Reversing xmin and xmax.
4fill in blank
hard

Fill both blanks to create a dictionary that sets x-axis limits from 1 to 4 and y-axis limits from 10 to 20.

Matplotlib
limits = {'xlim': ([1], [2]), 'ylim': (10, 20)}
Drag options to blanks, or click blank then click option'
A1
B4
C10
D20
Attempts:
3 left
💡 Hint
Common Mistakes
Using y-axis values for x-axis limits.
Swapping the order of limits.
Using strings instead of numbers.
5fill in blank
hard

Fill all three blanks to set x-axis limits from 0 to 5 and y-axis limits from -2 to 3 using plt.axis().

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.axis([[1], [2], [3], 3])
plt.show()
Drag options to blanks, or click blank then click option'
A0
B5
C-2
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of limits.
Using incorrect values for axis limits.
Forgetting that axis expects a list.