More Plot Types: eventplot, broken_barh, stairs
Beyond lines and bars, Matplotlib ships specialized plot types — eventplot for timelines, broken_barh for Gantt charts, stairs for step outlines, and bxp for precomputed boxplots.
Learn More Plot Types: eventplot, broken_barh, stairs in our free Matplotlib course — a beginner-friendly interactive lesson with worked examples, a practice…
Part of the free Matplotlib course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
In this lesson you'll raster event timelines with ax.eventplot() , build Gantt-style rows with ax.broken_barh() , draw step outlines with ax.stairs() , and render boxplots from stats with ax.bxp() .
ax.eventplot() draws a tick at every position you give it — a raster . Hand it a single array for one row, or a list of arrays for several stacked rows, perfect for comparing when events fired across different sources.
What you'll see: three colored rows of vertical tick marks, one per sensor, each tick landing at the moment that sensor fired — an at-a-glance timeline of who triggered when.
ax.broken_barh(xranges, yrange) draws horizontal bars from (start, width) pairs at a given (y, height) . One call can place several segments — gaps and all — on a single row, which is exactly what a Gantt chart needs: one task per row spanning its active periods.
ax.stairs(values, edges) draws a step outline — the natural partner for np.histogram , which returns counts and bin edges. And when you only have summary statistics, ax.bxp() renders a boxplot from a list of stat dictionaries instead of raw data.
What you'll see: on the left a filled bell-shaped step outline drawn straight from the histogram counts, and on the right two boxplots built entirely from the median and quartile numbers — no raw samples required.
Replace each ___ to raster a single row of event times.
You passed an end point as the width. ✅ The tuple is (start, duration) — use the length, not the end coordinate.
❌ stairs: len(values) must equal len(edges) - 1
There is always one more edge than value. ✅ Use the counts, edges straight from np.histogram without trimming.
Each stats dict needs med , q1 , q3 , whislo , whishi . ✅ Supply all required keys (and fliers as a list).
Use broken_barh to chart two tasks, each with a gap, on their own rows.
Lesson complete — your plotting toolbox grew!
You rastered timelines with eventplot, built Gantt rows with broken_barh, drew step outlines with stairs, and rendered boxplots from precomputed stats with bxp.
🚀 Up next: Donut & Nested Pie Charts — turn pies into modern donuts and nested rings.
Practice quiz
What does ax.eventplot() draw?
- A filled area
- A raster of tick marks at given positions
- A pie chart
- A 3D surface
Answer: A raster of tick marks at given positions. eventplot draws a tick at every position, forming a raster like a spike train or timeline.
How do you make eventplot show several stacked rows?
- Call it many times
- Pass rows=3
- Use stack=True
- Pass a list of arrays, one per row
Answer: Pass a list of arrays, one per row. A list of arrays gives eventplot one row of ticks per array.
What does ax.broken_barh take as its first argument?
- A list of (start, width) pairs
- A single number
- Two y-values
- A colormap
Answer: A list of (start, width) pairs. broken_barh's first argument is a list of (start, width) horizontal segments.
Why is broken_barh ideal for Gantt charts?
- It logs the axis
- It draws pies
- One call can place several segments with gaps on one row
- It auto-sorts tasks
Answer: One call can place several segments with gaps on one row. Each task occupies one row and may have disconnected active periods, which broken_barh handles in one call.
What does ax.stairs(values, edges) draw?
- A scatter plot
- A step outline, like a histogram shape
- A smooth curve
- A pie chart
Answer: A step outline, like a histogram shape. stairs draws the outline of a step function from edges and values.
Which NumPy function pairs naturally with ax.stairs()?
- np.linspace
- np.sort
- np.mean
- np.histogram
Answer: np.histogram. np.histogram returns counts and bin edges, exactly what stairs(counts, edges) needs.
What does ax.bxp() take as input?
- A list of stat dictionaries (median, quartiles, whiskers)
- Raw observations
- A colormap
- A list of images
Answer: A list of stat dictionaries (median, quartiles, whiskers). bxp renders a boxplot from precomputed statistics, not raw data.
When would you choose ax.bxp() over ax.boxplot()?
- When data has no outliers
- When you want a log axis
- When you only have precomputed stats, not raw data
- When plotting a single point
Answer: When you only have precomputed stats, not raw data. boxplot computes quartiles from raw data; bxp accepts the summary stats you already have.
What relationship must hold between values and edges in ax.stairs()?
- They must be equal length
- values can be empty
- edges must be sorted descending
- len(edges) is one more than len(values)
Answer: len(edges) is one more than len(values). There is always one more edge than value, just like histogram bins.
In a broken_barh tuple, what does the second number represent?
- The y-position
- The duration (width), not the end point
- The color
- The row height
Answer: The duration (width), not the end point. Each (start, width) tuple uses a duration as the second value, not an end coordinate.