Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AndreasLR opened this issue May 14, 2024 · 2 comments

Comments

@AndreasLR
Copy link

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

@tacaswell
Copy link
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.

@tacaswell tacaswell added this to the v3.9.1 milestone May 14, 2024
@tacaswell
Copy link
Member

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

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

No branches or pull requests

2 participants