0
0
Matplotlibdata~10 mins

Inverted axes 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 invert the y-axis in the plot.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.[1]()
plt.show()
Drag options to blanks, or click blank then click option'
Ainvert_yaxis
Binvert
Cinvert_axis
Dinvert_xaxis
Attempts:
3 left
💡 Hint
Common Mistakes
Using invert_xaxis() instead of invert_yaxis()
Using a non-existent method like invert_axis()
2fill in blank
medium

Complete the code to invert the x-axis using the Axes object.

Matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 6])
ax.[1]()
plt.show()
Drag options to blanks, or click blank then click option'
Ainvert_yaxis
Bflip_xaxis
Cinvert_axis
Dinvert_xaxis
Attempts:
3 left
💡 Hint
Common Mistakes
Using invert_yaxis() when x-axis inversion is needed
Using a method that does not exist like flip_xaxis()
3fill in blank
hard

Fix the error in the code to invert the y-axis correctly.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.[1]()
plt.show()
Drag options to blanks, or click blank then click option'
Ainvert_axis
Binvert_xaxis
Cinvert_yaxis
Dinvertyaxis
Attempts:
3 left
💡 Hint
Common Mistakes
Misspelling the method name as invertyaxis
Using invert_axis which does not exist
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps numbers to their squares only if the number is less than 4.

Matplotlib
squares = {x: x[1]2 for x in range(1, 6) if x [2] 4}
Drag options to blanks, or click blank then click option'
A**
B<
C>
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication (*) instead of exponentiation (**)
Using greater than (>) instead of less than (<)
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase letters to their ASCII values only if the ASCII value is greater than 65.

Matplotlib
ascii_map = [1]: ord([3]) for [1] in 'ABCDEF' if ord([3]) [2] 65}
Drag options to blanks, or click blank then click option'
Aletter
B>
Dord
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names
Using less than operator instead of greater than