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

Pandas hexbin plot lacks X axis labels in IPython Notebook #8653

Closed
levitsky opened this issue Jul 23, 2015 · 11 comments
Closed

Pandas hexbin plot lacks X axis labels in IPython Notebook #8653

levitsky opened this issue Jul 23, 2015 · 11 comments
Milestone

Comments

@levitsky
Copy link

When using pandas.DataFrame.plot() with kind='hexbin', the resulting plot sometimes has no X tick labels and on X axis label. This is observed in IPython Notebook (ipython version 3.2.0) with Python 3.4, matplotlib 1.4.3, with %pylab --no-import-all inline.
The same code produces a correct plot in IPython terminal on the same setup, with %pylab --no-import-all. This happens only on some dataframes, here's the code I run:

df = pd.read_csv('/tmp/example.csv', index_col=0)
df.plot('x', 'y', kind='hexbin', gridsize=10)

Here's the df:

           x           y
0  18.378351  111.080217
1  17.371567  118.277121
2  24.659952  169.528504
3  31.774163  310.880044
4  17.181311  113.618851
5  20.455473  149.341431
6  18.218108  132.492567
7  23.453792  157.083139
8  25.340805  158.190820

And here's the example.csv file used. The plot from the Notebook is below. Also, here is another fellow with the same problem.

image

@takluyver
Copy link
Member

Failed to reproduce on IPython master, Python 3.4, mpl 1.4.2 and pandas 0.15.0.

screenshot from 2015-07-23 12 57 32

@levitsky
Copy link
Author

I have reproduced it with IPython master (is that correct that I need jupyter/notebook to run the notebook server?).
I installed both from git master into a virtualenv (happened to be Python 2.7) and still see the same problem. Here's IPython.sys_info() from the notebook:

{'commit_hash': u'3e49b3c',
 'commit_source': 'installation',
 'default_encoding': 'UTF-8',
 'ipython_path': '/home/lev/test_venv/lib/python2.7/site-packages/IPython',
 'ipython_version': '4.0.0-dev',
 'os_name': 'posix',
 'platform': 'Linux-4.0.7-2-ARCH-x86_64-with-glibc2.2.5',
 'sys_executable': '/home/lev/test_venv/bin/python2',
 'sys_platform': 'linux2',
 'sys_version': '2.7.10 (default, May 26 2015, 04:16:29) \n[GCC 5.1.0]'}

And here's the whole notebook.

@takluyver
Copy link
Member

What's the pandas version? Could this be something that has changed in pandas?

@levitsky
Copy link
Author

Pandas version is 0.16.2. It might be dependent on pandas version for all I know (which is next to nothing), all I can say is the plot looks fine when plotted from IPython console, so it must be notebook-related and it manifests with 3.2 and 4.0-dev, at least for me.

@takluyver
Copy link
Member

It must be notebook related, but it might be something in pandas or mpl that is just triggered by the notebook.

@jreback, @tacaswell, any idea what might cause the X-axis labels and tick labels to go missing like this?

@levitsky
Copy link
Author

Another thing: the labels don't disappear with colobar=False. Updated the linked gist/notebook.

@tacaswell
Copy link
Contributor

That is odd...

x, y = np.random.randn(2, 122)
fig, ax = plt.subplots()
hx = ax.hexbin(x, y, cmap='Greens', gridsize=10)
fig.colorbar(hx)
plt.show()

works correctly in the notebook with both inline and notebook.

@levitsky
Copy link
Author

Yes, it only happens when called from DataFrame.plot().
However, when doing ax = df.plot('x', 'y', kind='hexbin', gridsize=10), ax.get_xlabel() returns a non-empty value as expected, and ax.get_xticklabels() also returns a correct list, although labels are not displayed.

@BDannowitz
Copy link

I'm seeing this problem as well with python 2.7, pandas 0.16.2.dev, and ipython version 3.1.0.

Looking to the documentation for pandas.DataFrame.plot, the only reference to the x labels and ticks being invisible is in the sharex option. So, I manually set sharex=False (which it should have been by default), and poof, the xlabel and xticks appeared.

Hopefully this helps tracking down the bug.

@takluyver
Copy link
Member

Thanks @BDannowitz . That makes it sound like there's an issue in pandas - does someone want to file an issue there? You can reference this issue for background.

@takluyver
Copy link
Member

Closing as it appears to be a pandas bug. Anyone who's still seeing it, follow along with pandas-dev/pandas#10678.

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

No branches or pull requests

4 participants