Skip to content
This repository

Fixed transoffset example from failing. #1111

Merged
merged 1 commit into from over 1 year ago

2 participants

Phil Elson Michael Droettboom
Phil Elson
Collaborator

This issue came about because the polar axes which had already been created via plt.subplot wasn't getting picked up with a simple plt.gca(projection='polar') due to different gridspecs. I have removed the use of the gridspec in the key comparison of gca, and added a few tests which cover these changes.

Fixes #1084.

Phil Elson pelson commented on the diff August 20, 2012
lib/matplotlib/pyplot.py
((7 lines not shown))
2086 2083
     """
2087  
-    resolution = kwargs.pop('resolution', 1)
2088  
-    ax = gca(polar=True, resolution=resolution)
1
Phil Elson Collaborator
pelson added a note August 20, 2012

This part wasn't necessary, but is out of date and redundant. I would be willing to put it back in if requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Michael Droettboom
Owner

Looks good.

Michael Droettboom
Owner

Merging.

Michael Droettboom mdboom merged commit dda4ab6 into from August 20, 2012
Michael Droettboom mdboom closed this August 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Aug 20, 2012
Phil Elson Fixed transoffset example from failing. 8bfdaf2
This page is out of date. Refresh to see the latest.
31  lib/matplotlib/figure.py
@@ -17,7 +17,7 @@
17 17
 import artist
18 18
 from artist import Artist, allow_rasterization
19 19
 from axes import Axes, SubplotBase, subplot_class_factory
20  
-from cbook import flatten, allequal, Stack, iterable, is_string_like
  20
+from cbook import allequal, Stack, iterable
21 21
 from matplotlib import _image
22 22
 import colorbar as cbar
23 23
 from image import FigureImage
@@ -27,15 +27,14 @@
27 27
 
28 28
 from legend import Legend
29 29
 from transforms import Affine2D, Bbox, BboxTransformTo, TransformedBbox
30  
-from projections import get_projection_names, get_projection_class, \
31  
-        process_projection_requirements
  30
+from projections import get_projection_names, process_projection_requirements
32 31
 from matplotlib.blocking_input import BlockingMouseInput, BlockingKeyMouseInput
33 32
 
34 33
 import matplotlib.cbook as cbook
35 34
 from matplotlib import docstring
36 35
 
37 36
 from operator import itemgetter
38  
-import os.path
  37
+
39 38
 
40 39
 docstring.interpd.update(projection_names = get_projection_names())
41 40
 
@@ -110,7 +109,8 @@ def add(self, key, a):
110 109
         a_existing = self.get(key)
111 110
         if a_existing is not None:
112 111
             Stack.remove(self, (key, a_existing))
113  
-            warnings.Warn(
  112
+            import warnings
  113
+            warnings.warn(
114 114
                     "key %s already existed; Axes is being replaced" % key)
115 115
             # I don't think the above should ever happen.
116 116
 
@@ -138,6 +138,7 @@ def __call__(self):
138 138
     def __contains__(self, a):
139 139
         return a in self.as_list()
140 140
 
  141
+
141 142
 class SubplotParams:
142 143
     """
143 144
     A class to hold the parameters for a subplot
@@ -212,8 +213,6 @@ def reset():
212 213
                 reset()
213 214
                 raise ValueError('bottom cannot be >= top')
214 215
 
215  
-
216  
-
217 216
     def _update_this(self, s, val):
218 217
         if val is None:
219 218
             val = getattr(self, s, None)
@@ -223,6 +222,7 @@ def _update_this(self, s, val):
223 222
 
224 223
         setattr(self, s, val)
225 224
 
  225
+
226 226
 class Figure(Artist):
227 227
 
228 228
     """
@@ -1077,13 +1077,9 @@ def gca(self, **kwargs):
1077 1077
         The following kwargs are supported for ensuring the returned axes
1078 1078
         adheres to the given projection etc., and for axes creation if
1079 1079
         the active axes does not exist:
  1080
+        
1080 1081
         %(Axes)s
1081 1082
 
1082  
-        .. note::
1083  
-            When specifying kwargs to ``gca`` to find the pre-created active
1084  
-            axes, they should be equivalent in every way to the kwargs which
1085  
-            were used in its creation.
1086  
-
1087 1083
         """
1088 1084
         ckey, cax = self._axstack.current_key_axes()
1089 1085
         # if there exists an axes on the stack see if it maches
@@ -1103,12 +1099,18 @@ def gca(self, **kwargs):
1103 1099
                 kwargs_copy = kwargs.copy()
1104 1100
                 projection_class, _, key = \
1105 1101
                         process_projection_requirements(self, **kwargs_copy)
  1102
+                
  1103
+                # let the returned axes have any gridspec by removing it from the key
  1104
+                ckey = ckey[1:]
  1105
+                key = key[1:]
  1106
+
1106 1107
                 # if the cax matches this key then return the axes, otherwise
1107 1108
                 # continue and a new axes will be created
1108 1109
                 if key == ckey and isinstance(cax, projection_class):
1109 1110
                     return cax
1110  
-
1111  
-        return self.add_subplot(111, **kwargs)
  1111
+                
  1112
+        # no axes found, so create one which spans the figure
  1113
+        return self.add_subplot(1, 1, 1, **kwargs)
1112 1114
 
1113 1115
     def sca(self, a):
1114 1116
         'Set the current axes to be a and return a'
@@ -1391,7 +1393,6 @@ def tight_layout(self, renderer=None, pad=1.08, h_pad=None, w_pad=None, rect=Non
1391 1393
         self.subplots_adjust(**kwargs)
1392 1394
 
1393 1395
 
1394  
-
1395 1396
 def figaspect(arg):
1396 1397
     """
1397 1398
     Create a figure with specified aspect ratio.  If *arg* is a number,
6  lib/matplotlib/pyplot.py
@@ -2080,12 +2080,8 @@ def polar(*args, **kwargs):
2080 2080
     Make a polar plot.  Multiple *theta*, *r* arguments are supported,
2081 2081
     with format strings, as in :func:`~matplotlib.pyplot.plot`.
2082 2082
 
2083  
-    An optional kwarg *resolution* sets the number of vertices to
2084  
-    interpolate between each pair of points.  The default is 1,
2085  
-    which disables interpolation.
2086 2083
     """
2087  
-    resolution = kwargs.pop('resolution', 1)
2088  
-    ax = gca(polar=True, resolution=resolution)
  2084
+    ax = gca(polar=True)
2089 2085
     ret = ax.plot(*args, **kwargs)
2090 2086
     draw_if_interactive()
2091 2087
     return ret
7  lib/matplotlib/tests/test_axes.py
... ...
@@ -1,7 +1,7 @@
1 1
 import numpy as np
2 2
 from numpy import ma
3 3
 import matplotlib
4  
-from matplotlib.testing.decorators import image_comparison, knownfailureif
  4
+from matplotlib.testing.decorators import image_comparison, cleanup
5 5
 import matplotlib.pyplot as plt
6 6
 
7 7
 
@@ -733,6 +733,7 @@ def test_scatter_plot():
733 733
     ax = plt.axes()
734 734
     ax.scatter([3, 4, 2, 6], [2, 5, 2, 3], c=['r', 'y', 'b', 'lime'], s=[24, 15, 19, 29])
735 735
 
  736
+@cleanup
736 737
 def test_as_mpl_axes_api():
737 738
     # tests the _as_mpl_axes api
738 739
     from matplotlib.projections.polar import PolarAxes
@@ -755,9 +756,7 @@ def _as_mpl_axes(self):
755 756
     assert type(ax) == PolarAxes, \
756 757
            'Expected a PolarAxes, got %s' % type(ax)
757 758
     ax_via_gca = plt.gca(projection=prj)
758  
-    # ideally, ax_via_gca is ax should be true. However, gca isn't
759  
-    # plummed like that. (even with projection='polar').
760  
-    assert ax_via_gca is not ax
  759
+    assert ax_via_gca is ax
761 760
     plt.close()
762 761
 
763 762
     # testing axes creation with gca
31  lib/matplotlib/tests/test_figure.py
... ...
@@ -1,6 +1,6 @@
1 1
 import matplotlib
2  
-from nose.tools import assert_equal
3  
-from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
  2
+from nose.tools import assert_equal, assert_is, assert_is_not
  3
+from matplotlib.testing.decorators import image_comparison, cleanup
4 4
 import matplotlib.pyplot as plt
5 5
 
6 6
 
@@ -38,3 +38,30 @@ def test_figure():
38 38
     # Return to the original; make sure the red line is not there.
39 39
     plt.figure('today')
40 40
     plt.close('tomorrow')
  41
+    
  42
+    
  43
+#@cleanup
  44
+def test_gca():
  45
+    fig = plt.figure()
  46
+
  47
+    ax1 = fig.add_axes([0, 0, 1, 1])
  48
+    assert_is(fig.gca(projection='rectilinear'), ax1)
  49
+    assert_is(fig.gca(), ax1)
  50
+    
  51
+    ax2 = fig.add_subplot(121, projection='polar')
  52
+    assert_is(fig.gca(), ax2)
  53
+    assert_is(fig.gca(polar=True), ax2)
  54
+    
  55
+    ax3 = fig.add_subplot(122)
  56
+    assert_is(fig.gca(), ax3)
  57
+
  58
+    # the final request for a polar axes will end up creating one
  59
+    # with a spec of 111.
  60
+    assert_is_not(fig.gca(polar=True), ax3)
  61
+    assert_is_not(fig.gca(polar=True), ax2)
  62
+    assert_equal(fig.gca().get_geometry(), (1, 1, 1))
  63
+    
  64
+    fig.sca(ax1)
  65
+    assert_is(fig.gca(projection='rectilinear'), ax1)
  66
+    assert_is(fig.gca(), ax1)
  67
+    
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.