Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Matplotlib tick-label warning with pandas 3.1.0

Open Beginner friendly
#582 0 comments 0 reactions 0 assignees View on GitHub

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
Tech stack
matplotlib, pandas, python

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ranaroussi/quantstats

All issues in ranaroussi/quantstats

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.