Skip to content

Warning when plotting a DataFrame with a single row #28905

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

Closed
madphysicist opened this issue Oct 10, 2019 · 4 comments
Closed

Warning when plotting a DataFrame with a single row #28905

madphysicist opened this issue Oct 10, 2019 · 4 comments
Labels

Comments

@madphysicist
Copy link

Closely related to #18306, item 9 in the listing, but probably not an exact duplicate. Based on StackOverflow question https://stackoverflow.com/q/58322744/2988730.

Simple code to reproduce:

import pandas as pd

df = pd.DataFrame([[1, 2, 3]], columns=['A', 'B', 'C'])
df.set_index('A', inplace=True)
df.plot()

This generates

UserWarning: Attempting to set identical left == right == 1.0 results in singular transformations; automatically expanding.
  ax.set_xlim(left, right)

Expected behavior is that the default xlims of [None, None] will let matplotlib compute its own limits. Instead, it appears that pandas is computing the limits based on the min and max of the data. This seems redundant at best, and incorrect in this particular case.

@jbrockmendel jbrockmendel added the Visualization plotting label Oct 10, 2019
@nrebena
Copy link
Contributor

nrebena commented Oct 11, 2019

Can you give the pandas version you use? I can reproduce this on 0.25x, but it seems to be fixed on master.

This is the output of pd.show_versions() for me:

INSTALLED VERSIONS ------------------ commit : 39602e7 python : 3.7.4.final.0 python-bits : 64 OS : Linux OS-release : 5.3.1-arch1-1-ARCH machine : x86_64 processor : byteorder : little LC_ALL : None LANG : fr_FR.UTF-8 LOCALE : fr_FR.UTF-8

pandas : unknown
numpy : 1.16.3
pytz : 2019.1
dateutil : 2.8.0
pip : 19.0.3
setuptools : 40.8.0
Cython : 0.29.13
pytest : 4.4.1
hypothesis : 4.18.2
sphinx : 1.8.5
blosc : 1.8.1
feather : None
xlsxwriter : 1.1.7
lxml.etree : 4.3.3
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.5.0
pandas_datareader: None
bs4 : 4.7.1
bottleneck : 1.2.1
fastparquet : 0.3.1
gcsfs : None
lxml.etree : 4.3.3
matplotlib : 3.0.3
numexpr : 2.6.9
odfpy : None
openpyxl : 2.6.2
pandas_gbq : None
pyarrow : 0.15.0
pytables : None
s3fs : 0.2.1
scipy : 1.2.1
sqlalchemy : 1.3.3
tables : 3.5.1
xarray : 0.12.1
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.1.7

@madphysicist
Copy link
Author

@nrebena My home machine:

d.show_versions()                                                      

INSTALLED VERSIONS
------------------
commit: None
python: 3.7.4.final.0
python-bits: 64
OS: Linux
OS-release: 5.2.14-arch2-1-ARCH
machine: x86_64
processor: 
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.2
pytest: None
pip: 19.2.2
setuptools: 41.0.1
Cython: None
numpy: 1.16.3
scipy: 1.2.1
pyarrow: None
xarray: None
IPython: 7.8.0
sphinx: 2.1.2
patsy: None
dateutil: 2.8.0
pytz: 2019.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.3
openpyxl: 2.5.14
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: None
lxml.etree: 4.4.1
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10.1
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

However, I was also able to reproduce on a Windows machine at work with pandas version 0.25.1, same as what the poster of the stack overflow question is using.

@kitchoi
Copy link

kitchoi commented Jan 3, 2020

I can reproduce on OSX with 0.25.3 as well.
Turning the UserWarning to an error allows me to pinpoint where the warning was triggered from:

ax.set_xlim(left, right)

I believe this is fixed on master. In my local copy of pandas 0.25.3, if I replicate the change in the master, i.e.

if self._is_ts_plot():
# reset of xlim should be used for ts data
# TODO: GH28021, should find a way to change view limit on xaxis
lines = _get_all_lines(ax)
left, right = _get_xlim(lines)
ax.set_xlim(left, right)

Then the UserWarning is gone.

@MarcoGorelli
Copy link
Member

I believe this is fixed on master

Can confirm - closing for now then

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

No branches or pull requests

5 participants