-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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: get UserWarning about FixedFormatter/FixedLocator in series.plot() #35684
Comments
Thanks @WestXu for the report. This appears to be for Matplotlib 3.3.0+ and persists on pandas master.
|
I got the same error with this code that plots dataframe columns (Series):
Result (note error at top): pd.show_versions() output: INSTALLED VERSIONScommit : f2ca0a2 pandas : 1.1.1 |
The problem comes from Matplotlib: I can reproduce the problem without using Pandas.
|
In my example above, if I add
the plot is the same as before, but I still get the UserWarning. |
You did not provide the data in your example, so I cannot reproduce it, but it seems to me that the problem originates with the x axis.
|
Thanks! Your second idea works, with no Warning (!), but I need to get the
code in there somehow so that the x axis labels are placed properly under the bars. I'm still trying various methods... Is there a matplotlib bug filed for this issue? I couldn't find it... |
There are many parameters to
|
ax.tick_params appears to have no params for anchoring the axis labels. My solution is below. The canvas.draw appears to have no effect. Your suggestion
produces the correct plot (as my original code did), but this UserWarning is thrown:
This code works, with no Warning:
All that was needed was the set_xticks. |
I think this may have been fixed in #35946 code sample from #35684 (comment)
maybe should add a release note and close cc @VirosaLi |
The issue has not been fixed. I had to include an "idle" set_yticks() command on my code (see below) to make the error go away in a very simple subroutine I use to format y-axis for my charts. Needless to say I don't want my code with such "noise". I hope it gets fixed soon.
|
@Rational-IM you're using pandas master? #35946 will be in 1.2 |
@TomAugspurger pardon my lack of knowledge but what it means to "use pandas master"? I'm using pandas 1.1.1 In [5]: pd.version |
It's the master branch from the git repository |
No - I'm using the latest version of pandas that I got from a regular anaconda update. When do you believe pandas 1.2.x will be released? The workaround is actually distorting the scale of some of my charts - therefore I will have to live with the warning until it is fixed. |
#35946 was a relatively small change. maybe could be backported. |
I'm using Am I missing something? import matplotlib.pyplot as plt
from matplotlib.ticker import FixedLocator, FixedFormatter
fig, ax = plt.subplots()
ax.scatter(0.5, 0.5)
x_formatter = FixedFormatter(['0', r'$T/2$', r'$T$'])
x_locator = FixedLocator([0, 0.5, 1])
ax.xaxis.set_major_formatter(x_formatter)
ax.xaxis.set_major_locator(x_locator)
ax.set_xlim(0, 1) |
Switch those two statements would fix the warning. ax.xaxis.set_major_locator(x_locator)
ax.xaxis.set_major_formatter(x_formatter) |
Wow, this was such an elegant solution. Using matplotlib to create simple bar charts, I kept receiving the 'FixedFormatter should only be used together with FixedLocator' error. using the canvas.draw() and tick_params() commands solved the issue immediately. Thank you! |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
Problem description
Got a UserWarning:
And to catch the Warning:
Got
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.8.5.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.104-microsoft-standard
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.5
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.1
setuptools : 49.3.1.post20200810
Cython : None
pytest : 6.0.1
hypothesis : None
sphinx : 3.2.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.2
html5lib : None
pymysql : 0.10.0
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.17.0
pandas_datareader: None
bs4 : 4.9.1
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.5.2
matplotlib : 3.3.0
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.4
pandas_gbq : None
pyarrow : 1.0.0
pytables : None
pytest : 6.0.1
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : 1.3.18
tables : 3.6.1
tabulate : 0.8.7
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: