Skip to content

[Bug]: Inconsistent Visualization of Intervals in ax.barh for Different Duration Widths #28223

Closed

Description

@AndreasLR

Bug summary

Issue Description:

When using ax.barh to visualize intervals, the function fails to display all intervals under certain conditions, which appears to be linked to the width of the intervals specified as duration. Specifically, intervals with a duration of 3 hours are not displayed properly, while increasing the duration to 5 hours results in correct visualization. This issue suggests a potential problem with how interval widths are handled or rendered in ax.barh.

Steps to Reproduce:
Refer to "code for reproduction"

Expected Behavior:

All intervals should be visualized consistently, regardless of their duration width.

Actual Behavior:

Intervals with a shorter duration (3 hours) are not visualized correctly, while longer durations (5 hours) are displayed as expected.

Code for reproduction

from datetime import datetime, timedelta
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

duration = timedelta(hours=3)
# duration = timedelta(hours=5)
ax.barh(y=0, width=duration, left=datetime(2024, 1, 1, 6))
ax.barh(y=1, width=duration, left=datetime(2024, 1, 1, 1))

plt.xticks(rotation=45)
plt.tight_layout()
plt.savefig('bug.png')

Actual outcome

Only one of two bars is rendered.
image

Expected outcome

I expect both bars to appear:
image

Additional information

No response

Operating system

Ubuntu and Manjaro

Matplotlib Version

3.8.4

Matplotlib Backend

agg

Python version

3.11.8

Jupyter version

No response

Installation

pip

Activity

  1. tacaswell commented on May 14, 2024

    @tacaswell
    Member

    This is a bug with the auto-limits as first bar starts immediately on the right limit

    If you draw the edges on the patches:

    ax.barh(y=0, width=duration, left=datetime(2024, 1, 1, 6), lw=10, ec='k')
    ax.barh(y=1, width=duration, left=datetime(2024, 1, 1, 1), lw=10, ec='k')

    you can see the left edge of the blue bar peaking out

    bug

    Why making the orange bar long enough to overlap "fixes" it is very surprising to me.

  2. added this to the v3.9.1 milestone on May 14, 2024
  3. tacaswell commented on May 14, 2024

    @tacaswell
    Member

    If you pan (or manually set the limits) the second bar renders correctly, it is just that it is off screen by default.

  4. QuLogic commented on Jun 12, 2024

    @QuLogic
    Member

    We discussed this on a call, and the problem isn't with units, but with the relative size of the positions vs the widths of the bars (i.e., when dates are made unitless, they are positioned at ~20000 vs a width of < 1 for hours). This causes some poor interaction with sticky edges. @ksunden will be opening a PR shortly.

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions