Bird
Raised Fist0
Matplotlibdata~20 mins

Broken axes concept in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Broken Axes Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of broken axes plot code
What will be the output of the following Python code using matplotlib's broken axes?
Matplotlib
import matplotlib.pyplot as plt
from brokenaxes import brokenaxes

fig = plt.figure(figsize=(6,4))
bax = brokenaxes(ylims=((0, 1), (3, 4)))
bax.plot([0, 1, 2, 3], [0.5, 0.7, 3.5, 3.8])
plt.show()
AA plot with two x-axis segments broken at 1 and 2, but continuous y-axis.
BA single continuous y-axis from 0 to 4 with all points plotted normally.
CA plot with two y-axis segments: one from 0 to 1 and another from 3 to 4, showing points connected across the break.
DA runtime error because brokenaxes does not support multiple y-axis limits.
Attempts:
2 left
💡 Hint
Broken axes allow you to skip ranges on an axis to focus on important data segments.
❓ data_output
intermediate
1:30remaining
Number of plotted points in broken axes
Given this code using brokenaxes, how many points will be visible on the plot?
Matplotlib
import matplotlib.pyplot as plt
from brokenaxes import brokenaxes

fig = plt.figure()
bax = brokenaxes(ylims=((0, 2), (5, 7)))
data_x = [0, 1, 2, 3, 4]
data_y = [1, 1.5, 3, 6, 6.5]
bax.plot(data_x, data_y)
plt.show()
A2 points
B3 points
C5 points
D4 points
Attempts:
2 left
💡 Hint
Points outside the broken y-axis limits are not shown.
🔧 Debug
advanced
2:00remaining
Identify the error in broken axes usage
What error will this code raise when trying to create a broken axes plot?
Matplotlib
import matplotlib.pyplot as plt
from brokenaxes import brokenaxes

fig = plt.figure()
bax = brokenaxes(xlims=((0, 2), (1, 3)))
bax.plot([0, 1, 2], [1, 2, 3])
plt.show()
ASyntaxError because of wrong tuple format
BValueError due to overlapping x-axis limits
CNo error, plot shows two broken x-axis segments
DTypeError because brokenaxes does not support xlims parameter
Attempts:
2 left
💡 Hint
Check if the axis limit ranges overlap or are invalid.
🚀 Application
advanced
1:30remaining
Use case for broken axes in data visualization
Which scenario best fits using broken axes in a plot?
ADisplaying data with a large gap in y-values to focus on two separate ranges.
BVisualizing data with only one small range of values.
CCreating a pie chart to show proportions.
DPlotting continuous data with no gaps or outliers.
Attempts:
2 left
💡 Hint
Broken axes help when data has gaps or outliers that distort scale.
🧠 Conceptual
expert
2:30remaining
Effect of broken axes on data interpretation
What is a potential risk when using broken axes in plots?
AIt can mislead viewers by visually compressing or skipping data ranges, hiding true differences.
BIt always improves clarity without any drawbacks.
CIt causes plots to be unreadable due to overlapping axis labels.
DIt prevents plotting multiple lines on the same graph.
Attempts:
2 left
💡 Hint
Think about how skipping axis ranges affects perception.

Practice

(1/5)
1. What is the main purpose of using broken axes in matplotlib plots?
easy
A. To skip unimportant data ranges and focus on key parts
B. To add 3D effects to the plot
C. To change the color scheme automatically
D. To animate the plot over time

Solution

  1. Step 1: Understand the concept of broken axes

    Broken axes are used to skip over parts of the axis where data is not important or has large gaps.
  2. Step 2: Identify the main purpose

    This helps to focus on important data ranges without showing the entire axis continuously.
  3. Final Answer:

    To skip unimportant data ranges and focus on key parts -> Option A
  4. Quick Check:

    Broken axes = skip gaps [OK]
Hint: Broken axes hide gaps to highlight important data [OK]
Common Mistakes:
  • Thinking broken axes add 3D or animation
  • Confusing broken axes with color changes
  • Assuming broken axes zoom in automatically
2. Which of the following is the correct way to import the brokenaxes package to use brokenaxes(...) directly for creating broken axes plots?
easy
A. from brokenaxes import BrokenAxes
B. import brokenaxes as ba
C. from brokenaxes import brokenaxes
D. import matplotlib.brokenaxes as ba

Solution

  1. Step 1: Recall the correct import syntax

    The brokenaxes package provides the brokenaxes function to create broken axes plots.
  2. Step 2: Identify the correct import statement

    The correct way is from brokenaxes import brokenaxes to access the function directly.
  3. Final Answer:

    from brokenaxes import brokenaxes -> Option C
  4. Quick Check:

    Import brokenaxes function = from brokenaxes import brokenaxes [OK]
Hint: Import brokenaxes function directly from brokenaxes [OK]
Common Mistakes:
  • Using capital 'BrokenAxes' instead of 'brokenaxes'
  • Trying to import from matplotlib instead of brokenaxes
  • Using wrong import syntax causing ImportError
3. What will the following code output?
from brokenaxes import brokenaxes
import matplotlib.pyplot as plt

bax = brokenaxes(ylims=((0, 2), (8, 10)))
bax.plot([0, 1, 2, 3], [1, 1.5, 9, 9.5])
plt.show()
medium
A. A plot with y-axis broken between 2 and 8 showing points near 1 and 9
B. A plot with continuous y-axis from 0 to 10
C. An error because ylims must be a single tuple
D. A plot with x-axis broken between 2 and 8

Solution

  1. Step 1: Analyze the ylims parameter

    The ylims=((0, 2), (8, 10)) means the y-axis is broken to show two ranges: 0 to 2 and 8 to 10, skipping 2 to 8.
  2. Step 2: Understand the plotted points

    The y-values are 1, 1.5, 9, and 9.5, which fit into the two visible y-axis ranges.
  3. Final Answer:

    A plot with y-axis broken between 2 and 8 showing points near 1 and 9 -> Option A
  4. Quick Check:

    ylims tuple of ranges = broken y-axis [OK]
Hint: ylims with tuples creates breaks on y-axis [OK]
Common Mistakes:
  • Assuming y-axis is continuous without breaks
  • Confusing x-axis and y-axis breaks
  • Expecting an error from tuple ylims
4. Identify the error in this code snippet that tries to create broken axes:
from brokenaxes import brokenaxes
import matplotlib.pyplot as plt

bax = brokenaxes(xlims=(0, 2), (5, 7))
bax.plot([1, 6], [10, 20])
plt.show()
medium
A. plt.show() must be called before plot
B. plot function requires x and y to be the same length
C. BrokenAxes cannot be used with xlims parameter
D. xlims should be a tuple of tuples, not separate tuples

Solution

  1. Step 1: Check the xlims argument syntax

    The code uses xlims=(0, 2), (5, 7) which is invalid syntax; it should be a single tuple containing tuples like xlims=((0, 2), (5, 7)).
  2. Step 2: Confirm other parts are correct

    The plot call and plt.show() are correct; the error is only in xlims syntax.
  3. Final Answer:

    xlims should be a tuple of tuples, not separate tuples -> Option D
  4. Quick Check:

    xlims syntax = tuple of tuples [OK]
Hint: Use double parentheses for xlims tuple of ranges [OK]
Common Mistakes:
  • Passing multiple tuples without enclosing in one tuple
  • Mixing up xlims and ylims syntax
  • Calling plt.show() too early
5. You have data with y-values clustered around 0-3 and 50-55, with a large gap in between. How would you create a broken y-axis to show both clusters clearly using brokenaxes?
hard
A. Plot two separate figures for each cluster
B. Use ylims=((0, 3), (50, 55)) when creating brokenaxes
C. Use xlims=((0, 3), (50, 55)) to break x-axis instead
D. Use ylims=(0, 55) to show full range without breaks

Solution

  1. Step 1: Identify the axis to break

    The gap is in y-values, so the y-axis needs to be broken to skip the large gap between 3 and 50.
  2. Step 2: Set ylims with two ranges

    Using ylims=((0, 3), (50, 55)) creates a broken y-axis showing both clusters clearly.
  3. Final Answer:

    Use ylims=((0, 3), (50, 55)) when creating brokenaxes -> Option B
  4. Quick Check:

    Broken y-axis = ylims tuple of ranges [OK]
Hint: Set ylims with two ranges to break y-axis gaps [OK]
Common Mistakes:
  • Breaking x-axis instead of y-axis
  • Using single continuous ylims hiding gap
  • Plotting separate figures unnecessarily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard