Skip to content
This repository

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

Merged
merged 2 commits into from over 1 year ago

4 participants

Jae-Joon Lee Michael Droettboom Phil Elson Eric Firing
Jae-Joon Lee
Owner

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

Michael Droettboom
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.

Phil Elson pelson commented on the diff August 30, 2012
lib/matplotlib/axes.py
@@ -7660,6 +7660,14 @@ def table(self, **kwargs):
7660 7660
         """
7661 7661
         return mtable.table(self, **kwargs)
7662 7662
 
  7663
+    def _make_twin_axes(self, *kl, **kwargs):
  7664
+        """
  7665
+        make a twinx axes of self. This is used for twinx and twiny.
  7666
+        """
  7667
+        ax2 = self.figure.add_axes(self.get_position(True), *kl, **kwargs)
  7668
+        return ax2
  7669
+
  7670
+
1
Phil Elson Collaborator
pelson added a note August 30, 2012

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
Phil Elson pelson commented on the diff August 30, 2012
lib/matplotlib/axes.py
@@ -8874,6 +8880,13 @@ def label_outer(self):
8874 8880
             label.set_visible(firstcol)
8875 8881
 
8876 8882
 
1
Phil Elson Collaborator
pelson added a note August 30, 2012

and here.

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

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

Eric Firing efiring merged commit d8dda52 into from September 01, 2012
Eric Firing efiring closed this September 01, 2012
Eric Firing
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.
4  doc/api/api_changes.rst
Source Rendered
@@ -120,6 +120,10 @@ Changes in 1.2.x
120 120
   ``ax.transData + ax.transAxes.inverted()`` (depth is a new concept, but had it existed 
121 121
   it would return 4 for this example).      
122 122
 
  123
+* ``twinx`` and ``twiny`` now returns an instance of SubplotBase if
  124
+  parent axes is an instance of SubplotBase.
  125
+  
  126
+
123 127
 Changes in 1.1.x
124 128
 ================
125 129
 
21  lib/matplotlib/axes.py
@@ -7660,6 +7660,14 @@ def table(self, **kwargs):
7660 7660
         """
7661 7661
         return mtable.table(self, **kwargs)
7662 7662
 
  7663
+    def _make_twin_axes(self, *kl, **kwargs):
  7664
+        """
  7665
+        make a twinx axes of self. This is used for twinx and twiny.
  7666
+        """
  7667
+        ax2 = self.figure.add_axes(self.get_position(True), *kl, **kwargs)
  7668
+        return ax2
  7669
+
  7670
+
7663 7671
     def twinx(self):
7664 7672
         """
7665 7673
         Call signature::
@@ -7676,8 +7684,7 @@ def twinx(self):
7676 7684
             events are only called for the artists in the top-most axes.
7677 7685
         """
7678 7686
 
7679  
-        ax2 = self.figure.add_axes(self.get_position(True), sharex=self,
7680  
-            frameon=False)
  7687
+        ax2 = self._make_twin_axes(sharex=self, frameon=False)
7681 7688
         ax2.yaxis.tick_right()
7682 7689
         ax2.yaxis.set_label_position('right')
7683 7690
         ax2.yaxis.set_offset_position('right')
@@ -7701,8 +7708,7 @@ def twiny(self):
7701 7708
             events are only called for the artists in the top-most axes.
7702 7709
         """
7703 7710
 
7704  
-        ax2 = self.figure.add_axes(self.get_position(True), sharey=self,
7705  
-            frameon=False)
  7711
+        ax2 = self._make_twin_axes(sharey=self, frameon=False)
7706 7712
         ax2.xaxis.tick_top()
7707 7713
         ax2.xaxis.set_label_position('top')
7708 7714
         self.xaxis.tick_bottom()
@@ -8874,6 +8880,13 @@ def label_outer(self):
8874 8880
             label.set_visible(firstcol)
8875 8881
 
8876 8882
 
  8883
+    def _make_twin_axes(self, *kl, **kwargs):
  8884
+        """
  8885
+        make a twinx axes of self. This is used for twinx and twiny.
  8886
+        """
  8887
+        ax2 = self.figure.add_subplot(self.get_subplotspec(), *kl, **kwargs)
  8888
+        return ax2
  8889
+
8877 8890
 
8878 8891
 _subplot_classes = {}
8879 8892
 def subplot_class_factory(axes_class=None):
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.