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

The height of axes of colorbars and parent plots do not exactly match in the inline backend #11215

Open
javadnoorb opened this issue Jul 4, 2018 · 0 comments

Comments

@javadnoorb
Copy link

javadnoorb commented Jul 4, 2018

When I run the following in Jupyter notebook:

%matplotlib inline
import numpy as np
import matplotlib.pyplot as pl

random_array = np.random.random((100, 100))
fig = pl.pcolormesh(random_array);
cbar = pl.colorbar();
points = fig.axes.get_position().get_points()
cbar_points = cbar.ax.get_position().get_points()
print(points[0,1], cbar_points[0,1])

I end up with:

0.125 0.1250000000000001

and the following figure:
image

Since the above two numbers are not equal, the height of the bottom of the figure doesn't exactly match the bottom of the colorbar.

This apparently is an IPython inline backend issue. Because when I try the above code but comment out the magic function I get equal values:

0.10999999999999999 0.10999999999999999

This is not a very obvious behavior and leads to undesirable outcome in Pandas plots. Pandas determines existence of the components of a figure (such as subplots and colorbars) by comparing their heights. So if colorbar and parent figure do not have the exact same vertical coordinates it will imply that a super tiny extra subfigure is present right underneath the colorbar. This in turn leads to erroneous behavior of sharex argument, leading to missing axis labels as noted here and here. I have proposed a PR on pandas page to deal with this. But since this is stemming from how IPython interacts with matplotlib, I was wondering if there is any interest to dig into its roots in IPython?

@javadnoorb javadnoorb changed the title Floats with similar representation correspond to axes of colorbars and parent plots. The height of axes of colorbars and parent plots do not exactly match in the inline backend Jul 4, 2018
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

1 participant