0
0
Matplotlibdata~10 mins

Custom tick formatters 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 import the correct module for custom tick formatting in matplotlib.

Matplotlib
from matplotlib.ticker import [1]
Drag options to blanks, or click blank then click option'
AFuncFormatter
BLinearLocator
CMaxNLocator
DMultipleLocator
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a locator class instead of a formatter.
Using a class that controls tick positions, not formatting.
2fill in blank
medium

Complete the code to define a function that formats ticks by adding a dollar sign before the value.

Matplotlib
def currency_format(x, pos):
    return [1]
Drag options to blanks, or click blank then click option'
A"$" + x
B"$" + str
C"$" + str(x)
D"$" + f"{x}"
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to concatenate a string with a number directly.
Using incorrect string formatting syntax.
3fill in blank
hard

Fix the error in the code to apply the custom formatter to the x-axis.

Matplotlib
ax.xaxis.set_major_formatter([1](currency_format))
Drag options to blanks, or click blank then click option'
AFormatStrFormatter
BFixedFormatter
CScalarFormatter
DFuncFormatter
Attempts:
3 left
💡 Hint
Common Mistakes
Using a formatter class that expects a format string instead of a function.
Not wrapping the function with a formatter class.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that formats numbers as percentages if greater than 0.5.

Matplotlib
percent_dict = {num: f"[1]%" for num in numbers if num [2] 0.5}
Drag options to blanks, or click blank then click option'
Aint(num * 100)
B>
C<
Dround(num * 100)
Attempts:
3 left
💡 Hint
Common Mistakes
Using the less than operator instead of greater than.
Not converting the number to an integer before formatting.
5fill in blank
hard

Fill all three blanks to create a custom formatter that shows values with 2 decimals and a percent sign only if value is less than 1.

Matplotlib
def custom_percent(x, pos):
    if x [1] 1:
        return f"{x * 100:[2][3]"
    else:
        return str(x)
Drag options to blanks, or click blank then click option'
A<
B.2f
C%
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using the greater than operator instead of less than.
Forgetting to multiply by 100 before formatting.
Incorrect string formatting syntax.