Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 2 commits into from

4 participants

@leejjoon
Owner

This is to address #1165.
Not sure if there will be some regression issue as its return type is different.

@mdboom
Owner

This doesn't affect any of the regression tests, but I think it would be worth noting the API change in the docs/api/api_changes.rst docs.

@pelson pelson commented on the diff
lib/matplotlib/axes.py
@@ -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
+
+
@pelson Collaborator
pelson added a note

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@pelson pelson commented on the diff
lib/matplotlib/axes.py
@@ -8874,6 +8880,13 @@ def label_outer(self):
label.set_visible(firstcol)
@pelson Collaborator
pelson added a note

and here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@pelson
Collaborator

+1 from me. Seems like a sensible solution to the problem.

@efiring efiring merged commit d8dda52 into from
@efiring
Owner

The white-space fixes can be done later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 4 deletions.
  1. +4 −0 doc/api/api_changes.rst
  2. +17 −4 lib/matplotlib/axes.py
View
4 doc/api/api_changes.rst
@@ -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
================
View
21 lib/matplotlib/axes.py
@@ -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
+
+
@pelson Collaborator
pelson added a note

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
def twinx(self):
"""
Call signature::
@@ -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')
@@ -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()
@@ -8874,6 +8880,13 @@ def label_outer(self):
label.set_visible(firstcol)
@pelson Collaborator
pelson added a note

and here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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):
Something went wrong with that request. Please try again.