Skip to content
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: xlim and ylim not restricting plot area #40781

Open
3 tasks done
regmibijay opened this issue Apr 5, 2021 · 5 comments
Open
3 tasks done

BUG: xlim and ylim not restricting plot area #40781

regmibijay opened this issue Apr 5, 2021 · 5 comments
Labels
Bug Error Reporting Incorrect or improved errors from pandas Visualization plotting

Comments

@regmibijay
Copy link

regmibijay commented Apr 5, 2021

  • 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

df = pd.read_csv(myfile) #contains 2 columns, Time in ms and Voltage in mV
xlabel = "Time in ms"
ylabel = "Volate in mV"
xlim = [0,120]
ylim = [0,8]
df.plot(x = "Time", xlabel= xlabel, ylabel=ylabel, xlim = xlim, ylim = ylim, kind="line")
plt.show()

Problem description

I am plotting a large dataset using dataframe.plot() in pandas. Dataset contains data in csv format. As per documentation, I specify xlim and ylim as arg in df.plot. Now the axes take the xlim and ylim values accordingly but the figure does not scale to these values and plot shows some part of of graph but not the area defined by 'xlim' and 'ylim'.

without xlim :
image
with xlim set :
image
sample files here: samples
project: project

Expected Output

I want to plot only the specified area. In my example image it would be the spike.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : f2c8480
python : 3.9.2.final.0
python-bits : 64
OS : Linux
OS-release : 4.4.0-19041-Microsoft
Version : #488-Microsoft Mon Sep 01 13:43:00 PST 2020
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.2.3
numpy : 1.20.2
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 52.0.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.22.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.1
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@regmibijay regmibijay added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 5, 2021
@regmibijay regmibijay changed the title BUG: BUG: xlim and ylim not restricting plot area Apr 5, 2021
@rhshadrach
Copy link
Member

I think it should be ylim=[0, 8e-6]. Although I'm confused on the y-axis being labeled by 1e-6 in your second plot.

@rhshadrach
Copy link
Member

I'm not able to duplicate on master; with ylim=[0, 8] or ylim=[0, 8e-6]. For the former, I get a line indecipherable from y=0; for the latter I get the expected output:

image

@rhshadrach rhshadrach added the Visualization plotting label Apr 6, 2021
@regmibijay
Copy link
Author

after comment from @rhshadrach, I was successful in debugging what was happening. I was processing command line parameters with argparse and this behaviour seems to occur when the supplied xlim and ylim data have string elements and not int or float type. We should maybe either raise ValueError or convert passed data to int or float.

@rhshadrach rhshadrach added Error Reporting Incorrect or improved errors from pandas and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 11, 2021
@rhshadrach
Copy link
Member

Thanks for reporting back @regmibijay - I agree and think either are a workable solution, although I personally would lean toward raising if the values are not numeric. Would you be interested in submitting a PR to implement the patch?

@regmibijay
Copy link
Author

I am working on this issue and will address with a PR soon!

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