Skip to content

VIS: only apply shared axes handling on actual SubplotAxes #11561

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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
VIS: only apply shared axes handling on actual SubplotAxes
To fix bugs when dealing with plain Axes objects (GH11556, GH11520)
  • Loading branch information
jorisvandenbossche committed Nov 13, 2015
commit a145a59b4ee18f7837a37a1282ee949366ea0fbd
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v0.17.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ Bug Fixes


- Fix regression in setting of ``xticks`` in ``plot`` (:issue:`11529`).

- Fix plotting issues when having plain ``Axes`` instances instead of
``SubplotAxes`` (:issue:`11520`, :issue:`11556`).



Expand Down
29 changes: 29 additions & 0 deletions pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3678,6 +3678,35 @@ def test_invalid_colormap(self):
with tm.assertRaises(ValueError):
df.plot(colormap='invalid_colormap')

def test_plain_axes(self):

# supplied ax itself is a SubplotAxes, but figure contains also
# a plain Axes object (GH11556)
fig, ax = self.plt.subplots()
fig.add_axes([0.2, 0.2, 0.2, 0.2])
Series(rand(10)).plot(ax=ax)

# suppliad ax itself is a plain Axes, but because the cmap keyword
# a new ax is created for the colorbar -> also multiples axes (GH11520)
df = DataFrame({'a': randn(8), 'b': randn(8)})
fig = self.plt.figure()
ax = fig.add_axes((0,0,1,1))
df.plot(kind='scatter', ax=ax, x='a', y='b', c='a', cmap='hsv')

# other examples
fig, ax = self.plt.subplots()
from mpl_toolkits.axes_grid1 import make_axes_locatable
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
Series(rand(10)).plot(ax=ax)
Series(rand(10)).plot(ax=cax)

fig, ax = self.plt.subplots()
from mpl_toolkits.axes_grid.inset_locator import inset_axes
iax = inset_axes(ax, width="30%", height=1., loc=3)
Series(rand(10)).plot(ax=ax)
Series(rand(10)).plot(ax=iax)


@tm.mplskip
class TestDataFrameGroupByPlots(TestPlotBase):
Expand Down
10 changes: 6 additions & 4 deletions pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ def _post_plot_logic(self, ax, data):
def _adorn_subplots(self):
"""Common post process unrelated to data"""
if len(self.axes) > 0:
all_axes = self._get_axes()
all_axes = self._get_subplots()
nrows, ncols = self._get_axes_layout()
_handle_shared_axes(axarr=all_axes, nplots=len(all_axes),
naxes=nrows * ncols, nrows=nrows,
Expand Down Expand Up @@ -1467,11 +1467,13 @@ def _get_errorbars(self, label=None, index=None, xerr=True, yerr=True):
errors[kw] = err
return errors

def _get_axes(self):
return self.axes[0].get_figure().get_axes()
def _get_subplots(self):
from matplotlib.axes import Subplot
return [ax for ax in self.axes[0].get_figure().get_axes()
if isinstance(ax, Subplot)]

def _get_axes_layout(self):
axes = self._get_axes()
axes = self._get_subplots()
x_set = set()
y_set = set()
for ax in axes:
Expand Down