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

DOC: Hexbin creates inconsistent size of hexagons for nearly the same data, depending on distance from axis limits #44528

Open
2 of 3 tasks
stelios-c opened this issue Nov 19, 2021 · 3 comments
Labels

Comments

@stelios-c
Copy link

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

import pandas as pd
from io import StringIO
csv_data = "x,y\n1,1\n1,2\n2,1\n1,9\n9,1"
csv_data2 = "x,y\n1,1\n1,2\n2,1\n1,3\n3,1"
pd.read_csv(StringIO(csv_data)).plot(kind='hexbin',x='x',y='y',\
                   xlim=[-0.5,10.5],ylim=[0,10.5],\
                   gridsize=[10,10],sharex=False)
pd.read_csv(StringIO(csv_data2)).plot(kind='hexbin',x='x',y='y',\
                   xlim=[-0.5,10.5],ylim=[0,10.5],\
                   gridsize=[10,10],sharex=False)

Issue Description

csv_data gets plotted with big hexagons touching each other as expected. csv_data2 gets plotted with much smaller hexagons, probably because there is no data near the right xlim, upper ylim.

Expected Behavior

I was expecting the same size of hexagon for those two datasets

Installed Versions

INSTALLED VERSIONS

commit : 945c9ed
python : 3.7.10.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.0-18-cloud-amd64
Version : #1 SMP Debian 4.19.208-1 (2021-09-29)
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.4
numpy : 1.19.5
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3
setuptools : 58.2.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 : 3.0.2
IPython : 7.28.0
pandas_datareader: None
bs4 : None
bottleneck : 1.3.2
fsspec : 2021.10.1
fastparquet : None
gcsfs : 2021.10.1
matplotlib : 3.4.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 5.0.0
pyxlsb : None
s3fs : None
scipy : 1.7.1
sqlalchemy : 1.4.26
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.54.1

@stelios-c stelios-c added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 19, 2021
@stelios-c
Copy link
Author

hexbin_inconsistent

@Lstsk
Copy link

Lstsk commented Nov 21, 2021

Hello, I don't think this is a bug. The hexagon is getting small because it would have to adjust its size to fit data that is so close to each other. Perhaps, you could adjust the grid-size, xlim, and ylim to make the graph look better?

@mroeschke mroeschke added Closing Candidate May be closeable, needs more eyeballs Visualization plotting and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 21, 2021
@stelios-c
Copy link
Author

Thanks @Copastr . I'm trying to do an A/B type comparison so I want xlim and ylim to be the same. But I agree, it looks like grid size needs to be adjusted to the range of the data. Maybe this should be treated as a documentation bug because https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.hexbin.html only says

gridsizeint or tuple of (int, int), default 100
The number of hexagons in the x-direction. The corresponding number of hexagons in the y-direction is chosen in a way that the hexagons are approximately regular. Alternatively, gridsize can be a tuple with two elements specifying the number of hexagons in the x-direction and the y-direction.

This does not clarify that the hexagons are not all the way to xlim/ylim but only to the extent covered by the data.

@mroeschke mroeschke added Docs and removed Bug Closing Candidate May be closeable, needs more eyeballs labels Dec 27, 2021
@mroeschke mroeschke changed the title BUG: Hexbin creates inconsistent size of hexagons for nearly the same data, depending on distance from axis limits DOC: Hexbin creates inconsistent size of hexagons for nearly the same data, depending on distance from axis limits Dec 27, 2021
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

3 participants