Matplotlib tick-label warning with pandas 3.1.0
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Domain
- data-visualization
Research direction
The warning points to quantstats/_plotting/core.py:266 in the yearly returns plotting path. Read that code and reproduce the supplied example with the listed pandas and matplotlib versions. Check that the warning is gone and the year labels and plotted returns remain correct.
Written by the indexing model from the issue text.
Description
I got this warning after upgrading to pandas 3.1.0:
/path/to/python314/lib64/python3.14/site-packages/quantstats/_plotting/core.py:266: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator. Otherwise, ticks may be mislabeled.
ax.set_xticklabels(df.index.year)
Environment: Python 3.14, pandas 3.1.0, matplotlib 3.11.1, quantstats 0.0.86
Example
import pandas as pd
import quantstats as qs
r = pd.Series([0.1, -0.05], index=pd.date_range("2025", periods=2, freq="YE"))
qs.plots.yearly_returns(r, show=False)
I asked ChatGPT to suggest a fix and it said the following:
In quantstats/_plotting/core.py, replace:
Old:
df.plot(kind="bar", ax=ax, color=colors)
New:
df.set_axis(df.index.astype(str)).plot(kind="bar", ax=ax, color=colors)
No other changes required.
Pandas 3.1 introduced dynamic date ticks for datetime-indexed bar plots. Converting the plotting index to strings restores categorical tick positioning while preserving the original DataFrame and existing year-labeling logic.
This eliminates the warning without changing the plotted returns or chart appearance.
- Dominant language
- Python
- Stars
- 7.7k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ranaroussi/quantstats
-
Drawdown functions fail on supported RangeIndex inputsPossibly taken @Cyber-Marty claimed this 9 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ranaroussi/quantstats#575 ·
Maintainers usually reply within 1 day
-
Can the price/returns auto-detection tell a sub-$1 price series from a return series?Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
ranaroussi/quantstats#571 · 9 comments ·
Maintainers usually reply within 1 day
-
Monthly Return Heatmap Display Issue in VS CodeMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
ranaroussi/quantstats#520 ·
Maintainers usually reply within 1 day
-
[bug] EOY returns vs benchmark on time range longer than 10yPossibly taken @Geochelone666 claimed this 22 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 48/100
ranaroussi/quantstats#518 · 1 comment ·
Maintainers usually reply within 1 day
-
qs.stats.information_ratio() uses arithmetic mean instead of geometricPossibly taken @Whning0513 claimed this 116 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 72/100
ranaroussi/quantstats#514 · 3 comments ·
Maintainers usually reply within 1 day
All issues in ranaroussi/quantstats
Similar issues
-
type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
push_gh-pages fails on master branch on forksPossibly taken A pull request linked to this issue is open or already merged. Opengood first issue infrastructure
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
kuznia-rdzeni/coreblocks#1135 ·
-
good first issue server
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
documentation priority: high
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
a-lex-s/mealie-telegram-bot#54 ·
Maintainers usually reply within 1 day