Skip to content

Fix EOY Returns bar chart misalignment with x-axis labels#515

Open
edparcell wants to merge 1 commit intoranaroussi:mainfrom
edparcell:fix-eoy-bar-alignment
Open

Fix EOY Returns bar chart misalignment with x-axis labels#515
edparcell wants to merge 1 commit intoranaroussi:mainfrom
edparcell:fix-eoy-bar-alignment

Conversation

@edparcell
Copy link
Copy Markdown

@edparcell edparcell commented Apr 23, 2026

Summary

  • Fix x-axis label misalignment in the EOY Returns bar chart
  • When there are >10 years of data, labels were clustered on the left while bars appeared on the right

Root cause

df.plot(kind='bar') with a DatetimeIndex positions bars at internal integer offsets (e.g. 30, 31, 32...) rather than starting at 0. The label-thinning code in plot_returns_bars() then placed labels at np.arange(len(years)) (0, 1, 2...), creating a mismatch.

Fix

Use ax.get_xticks() to get the actual bar positions instead of assuming they start at 0. One-line change in quantstats/_plotting/core.py.

🤖 Generated with Claude Code

When plotting yearly returns as a bar chart, the x-axis tick labels
were misaligned with the bars. This happened because pandas
df.plot(kind='bar') with a DatetimeIndex positions bars at internal
integer offsets (e.g. 30, 31, 32...) rather than starting at 0.
The label-thinning code then placed labels at np.arange(len(years))
(0, 1, 2...), causing labels to cluster on the left while bars
appeared on the right.

Fix: use ax.get_xticks() to get the actual bar positions instead
of assuming they start at 0.
@edparcell
Copy link
Copy Markdown
Author

Before:
image

After:
image

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant