Skip to content

Subplot.twin[xy] returns a Subplot instance #1169

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

Merged
merged 2 commits into from
Sep 2, 2012
Merged
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
4 changes: 4 additions & 0 deletions doc/api/api_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ Changes in 1.2.x
``ax.transData + ax.transAxes.inverted()`` (depth is a new concept, but had it existed
it would return 4 for this example).

* ``twinx`` and ``twiny`` now returns an instance of SubplotBase if
parent axes is an instance of SubplotBase.


Changes in 1.1.x
================

Expand Down
21 changes: 17 additions & 4 deletions lib/matplotlib/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7660,6 +7660,14 @@ def table(self, **kwargs):
"""
return mtable.table(self, **kwargs)

def _make_twin_axes(self, *kl, **kwargs):
"""
make a twinx axes of self. This is used for twinx and twiny.
"""
ax2 = self.figure.add_axes(self.get_position(True), *kl, **kwargs)
return ax2


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know its picky, but would you mind putting 1 newline between methods and 2 newlines between top level classes/functions.

def twinx(self):
"""
Call signature::
Expand All @@ -7676,8 +7684,7 @@ def twinx(self):
events are only called for the artists in the top-most axes.
"""

ax2 = self.figure.add_axes(self.get_position(True), sharex=self,
frameon=False)
ax2 = self._make_twin_axes(sharex=self, frameon=False)
ax2.yaxis.tick_right()
ax2.yaxis.set_label_position('right')
ax2.yaxis.set_offset_position('right')
Expand All @@ -7701,8 +7708,7 @@ def twiny(self):
events are only called for the artists in the top-most axes.
"""

ax2 = self.figure.add_axes(self.get_position(True), sharey=self,
frameon=False)
ax2 = self._make_twin_axes(sharey=self, frameon=False)
ax2.xaxis.tick_top()
ax2.xaxis.set_label_position('top')
self.xaxis.tick_bottom()
Expand Down Expand Up @@ -8874,6 +8880,13 @@ def label_outer(self):
label.set_visible(firstcol)


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here.

def _make_twin_axes(self, *kl, **kwargs):
"""
make a twinx axes of self. This is used for twinx and twiny.
"""
ax2 = self.figure.add_subplot(self.get_subplotspec(), *kl, **kwargs)
return ax2


_subplot_classes = {}
def subplot_class_factory(axes_class=None):
Expand Down