[Bug]: broken_barh produces longer bars with smaller durations · Issue #32510 · matplotlib/matplotlib · GitHub
Skip to content

[Bug]: broken_barh produces longer bars with smaller durations #32510

Open

Description

@thisandthatuser

Bug summary

The broken_barh method appears to reproduce ranges inconsistently: given two durations, the larger one appears smaller, and in some cases even disappears.

Code for reproduction

# example 1
fig, ax = plt.subplots()

# broken_barh(xranges, (ypos, height))
ax.broken_barh([(-50, 0.02)], ("CPU 1", 0.5), align="center")
ax.broken_barh([(-50, 1e-12)], ("CPU 2", 0.5), align="center", color="tab:blue")
ax.broken_barh([(-50, 0.02)], ("CPU 3", 0.5), align="center", color="tab:blue")
ax.broken_barh([(50, 0.02)], ("CPU 4", 0.5), align="center")
ax.broken_barh([(50, 1e-12)], ("CPU 5", 0.5), align="center", color="tab:orange")
ax.broken_barh([(50, 0.02)], ("CPU 6", 0.5), align="center", color="tab:orange")
ax.set_xlim(-55, 55)
ax.invert_yaxis()  # order the bars from top to bottom
ax.set_title("Not defining the color seems to cause a bar not to show up!")
plt.show()

# example 2

fig, ax = plt.subplots()
# broken_barh(xranges, (ypos, height))
ax.broken_barh([(-50, 0.2)], ("CPU 1", 0.5), align="center")
ax.broken_barh([(-50, 1e-12)], ("CPU 2", 0.5), align="center", color="tab:blue")
ax.broken_barh([(-50, 0.2)], ("CPU 3", 0.5), align="center", color="tab:blue")
ax.broken_barh([(50, 0.2)], ("CPU 4", 0.5), align="center")
ax.broken_barh([(50, 1e-12)], ("CPU 5", 0.5), align="center", color="tab:orange")
ax.broken_barh([(50, 0.2)], ("CPU 6", 0.5), align="center", color="tab:orange")
ax.set_xlim(-55, 55)
ax.invert_yaxis()  # order the bars from top to bottom
ax.set_title("Not defining the color seems to affect how bars are shown!")
plt.show()

Actual outcome

Unlike in the example found on the website, not specifying a color seems to affect how bars are represented, from not drawing them to them having incoherent sizes.

Image Image

Expected outcome

I would expect a given duration to be represented exactly with the same size, irrespective of the color.

Additional information

I only tried two colors.

For now, I have fixed this by defining the colors in every case.

I have been using matplotlib 3.11 and python 3.11.

Operating system

Windows 11

Matplotlib Version

3.11.2

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.11.13

Jupyter version

No response

Installation

pip

Activity

  1. timhoffm commented on Oct 20, 2026

    @timhoffm
    Member

    This behavior follows from the technical implementation as PolyCollection. Each rectangle is a polygon in the collection. By default they have a facecolor, but not an edgecolor. Eaces that are less than a pixel are not rendered at all. Edge lines are always rendered. With the color argument you set both facecolor and edgecolor so that the edge line becomes visible. A bar with an edge line is wider than a bar without edge as the edge line is centered on the edge, and thus half the linewidth is "outside".

    This is a bit unfortunate, but I don't think we can change behavior here. The only thing we can do is document this better.

    Note that you can also set edgecolor="face" so that the edge becomes visible, but you don't have to specify a color explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions