Permalink
Browse files

Fixed transoffset example from failing.

  • Loading branch information...
1 parent 2847ad3 commit 8bfdaf21f5c34e246a326bb948c4854c9e3067d7 @pelson committed Aug 19, 2012
Showing with 49 additions and 26 deletions.
  1. +16 −15 lib/matplotlib/figure.py
  2. +1 −5 lib/matplotlib/pyplot.py
  3. +3 −4 lib/matplotlib/tests/test_axes.py
  4. +29 −2 lib/matplotlib/tests/test_figure.py
View
@@ -17,7 +17,7 @@
import artist
from artist import Artist, allow_rasterization
from axes import Axes, SubplotBase, subplot_class_factory
-from cbook import flatten, allequal, Stack, iterable, is_string_like
+from cbook import allequal, Stack, iterable
from matplotlib import _image
import colorbar as cbar
from image import FigureImage
@@ -27,15 +27,14 @@
from legend import Legend
from transforms import Affine2D, Bbox, BboxTransformTo, TransformedBbox
-from projections import get_projection_names, get_projection_class, \
- process_projection_requirements
+from projections import get_projection_names, process_projection_requirements
from matplotlib.blocking_input import BlockingMouseInput, BlockingKeyMouseInput
import matplotlib.cbook as cbook
from matplotlib import docstring
from operator import itemgetter
-import os.path
+
docstring.interpd.update(projection_names = get_projection_names())
@@ -110,7 +109,8 @@ def add(self, key, a):
a_existing = self.get(key)
if a_existing is not None:
Stack.remove(self, (key, a_existing))
- warnings.Warn(
+ import warnings
+ warnings.warn(
"key %s already existed; Axes is being replaced" % key)
# I don't think the above should ever happen.
@@ -138,6 +138,7 @@ def __call__(self):
def __contains__(self, a):
return a in self.as_list()
+
class SubplotParams:
"""
A class to hold the parameters for a subplot
@@ -212,8 +213,6 @@ def reset():
reset()
raise ValueError('bottom cannot be >= top')
-
-
def _update_this(self, s, val):
if val is None:
val = getattr(self, s, None)
@@ -223,6 +222,7 @@ def _update_this(self, s, val):
setattr(self, s, val)
+
class Figure(Artist):
"""
@@ -1077,13 +1077,9 @@ def gca(self, **kwargs):
The following kwargs are supported for ensuring the returned axes
adheres to the given projection etc., and for axes creation if
the active axes does not exist:
+
%(Axes)s
- .. note::
- When specifying kwargs to ``gca`` to find the pre-created active
- axes, they should be equivalent in every way to the kwargs which
- were used in its creation.
-
"""
ckey, cax = self._axstack.current_key_axes()
# if there exists an axes on the stack see if it maches
@@ -1103,12 +1099,18 @@ def gca(self, **kwargs):
kwargs_copy = kwargs.copy()
projection_class, _, key = \
process_projection_requirements(self, **kwargs_copy)
+
+ # let the returned axes have any gridspec by removing it from the key
+ ckey = ckey[1:]
+ key = key[1:]
+
# if the cax matches this key then return the axes, otherwise
# continue and a new axes will be created
if key == ckey and isinstance(cax, projection_class):
return cax
-
- return self.add_subplot(111, **kwargs)
+
+ # no axes found, so create one which spans the figure
+ return self.add_subplot(1, 1, 1, **kwargs)
def sca(self, a):
'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
self.subplots_adjust(**kwargs)
-
def figaspect(arg):
"""
Create a figure with specified aspect ratio. If *arg* is a number,
View
@@ -2080,12 +2080,8 @@ def polar(*args, **kwargs):
Make a polar plot. Multiple *theta*, *r* arguments are supported,
with format strings, as in :func:`~matplotlib.pyplot.plot`.
- An optional kwarg *resolution* sets the number of vertices to
- interpolate between each pair of points. The default is 1,
- which disables interpolation.
"""
- resolution = kwargs.pop('resolution', 1)
- ax = gca(polar=True, resolution=resolution)
+ ax = gca(polar=True)
ret = ax.plot(*args, **kwargs)
draw_if_interactive()
return ret
@@ -1,7 +1,7 @@
import numpy as np
from numpy import ma
import matplotlib
-from matplotlib.testing.decorators import image_comparison, knownfailureif
+from matplotlib.testing.decorators import image_comparison, cleanup
import matplotlib.pyplot as plt
@@ -733,6 +733,7 @@ def test_scatter_plot():
ax = plt.axes()
ax.scatter([3, 4, 2, 6], [2, 5, 2, 3], c=['r', 'y', 'b', 'lime'], s=[24, 15, 19, 29])
+@cleanup
def test_as_mpl_axes_api():
# tests the _as_mpl_axes api
from matplotlib.projections.polar import PolarAxes
@@ -755,9 +756,7 @@ def _as_mpl_axes(self):
assert type(ax) == PolarAxes, \
'Expected a PolarAxes, got %s' % type(ax)
ax_via_gca = plt.gca(projection=prj)
- # ideally, ax_via_gca is ax should be true. However, gca isn't
- # plummed like that. (even with projection='polar').
- assert ax_via_gca is not ax
+ assert ax_via_gca is ax
plt.close()
# testing axes creation with gca
@@ -1,6 +1,6 @@
import matplotlib
-from nose.tools import assert_equal
-from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
+from nose.tools import assert_equal, assert_is, assert_is_not
+from matplotlib.testing.decorators import image_comparison, cleanup
import matplotlib.pyplot as plt
@@ -38,3 +38,30 @@ def test_figure():
# Return to the original; make sure the red line is not there.
plt.figure('today')
plt.close('tomorrow')
+
+
+#@cleanup
+def test_gca():
+ fig = plt.figure()
+
+ ax1 = fig.add_axes([0, 0, 1, 1])
+ assert_is(fig.gca(projection='rectilinear'), ax1)
+ assert_is(fig.gca(), ax1)
+
+ ax2 = fig.add_subplot(121, projection='polar')
+ assert_is(fig.gca(), ax2)
+ assert_is(fig.gca(polar=True), ax2)
+
+ ax3 = fig.add_subplot(122)
+ assert_is(fig.gca(), ax3)
+
+ # the final request for a polar axes will end up creating one
+ # with a spec of 111.
+ assert_is_not(fig.gca(polar=True), ax3)
+ assert_is_not(fig.gca(polar=True), ax2)
+ assert_equal(fig.gca().get_geometry(), (1, 1, 1))
+
+ fig.sca(ax1)
+ assert_is(fig.gca(projection='rectilinear'), ax1)
+ assert_is(fig.gca(), ax1)
+

0 comments on commit 8bfdaf2

Please sign in to comment.