8000 Merge pull request #1111 from pelson/transoffset_fix · matplotlib/matplotlib@dda4ab6 · GitHub
[go: up one dir, main page]

Skip to content

Commit dda4ab6

Browse files
committed
Merge pull request #1111 from pelson/transoffset_fix
Fixed transoffset example from failing.
2 parents 9ae66ef + 8bfdaf2 commit dda4ab6

File tree

4 files changed

+49
-26
lines changed

4 files changed

+49
-26
lines changed

lib/matplotlib/figure.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import artist
1818
from artist import Artist, allow_rasterization
1919
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
2121
from matplotlib import _image
2222
import colorbar as cbar
2323
from image import FigureImage
@@ -27,15 +27,14 @@
2727

2828
from legend import Legend
2929
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
3231
from matplotlib.blocking_input import BlockingMouseInput, BlockingKeyMouseInput
3332

3433
import matplotlib.cbook as cbook
3534
from matplotlib import docstring
3635

3736
from operator import itemgetter
38-
import os.path
37+
3938

4039
docstring.interpd.update(projection_names = get_projection_names())
4140

@@ -110,7 +109,8 @@ def add(self, key, a):
110109
a_existing = self.get(key)
111110
if a_existing is not None:
112111
Stack.remove(self, (key, a_existing))
113-
warnings.Warn(
112+
import warnings
113+
warnings.warn(
114114
"key %s already existed; Axes is being replaced" % key)
115115
# I don't think the above should ever happen.
116116

@@ -138,6 +138,7 @@ def __call__(self):
138138
def __contains__(self, a):
139139
return a in self.as_list()
140140

141+
141142
class SubplotParams:
142143
"""
143144 8000
A class to hold the parameters for a subplot
@@ -212,8 +213,6 @@ def reset():
212213
reset()
213214
raise ValueError('bottom cannot be >= top')
214215

215-
216-
217216
def _update_this(self, s, val):
218217
if val is None:
219218
val = getattr(self, s, None)
@@ -223,6 +222,7 @@ def _update_this(self, s, val):
223222

224223
setattr(self, s, val)
225224

225+
226226
class Figure(Artist):
227227

228228
"""
@@ -1081,13 +1081,9 @@ def gca(self, **kwargs):
10811081
The following kwargs are supported for ensuring the returned axes
10821082
adheres to the given projection etc., and for axes creation if
10831083
the active axes does not exist:
1084+
10841085
%(Axes)s
10851086
1086-
.. note::
1087-
When specifying kwargs to ``gca`` to find the pre-created active
1088-
axes, they should be equivalent in every way to the kwargs which
1089-
were used in its creation.
1090-
10911087
"""
10921088
ckey, cax = self._axstack.current_key_axes()
10931089
# if there exists an axes on the stack see if it maches
@@ -1107,12 +1103,18 @@ def gca(self, **kwargs):
11071103
kwargs_copy = kwargs.copy()
11081104
projection_class, _, key = \
11091105
process_projection_requirements(self, **kwargs_copy)
1106+
1107+
# let the returned axes have any gridspec by removing it from the key
1108+
ckey = ckey[1:]
1109+
key = key[1:]
1110+
11101111
# if the cax matches this key then return the axes, otherwise
11111112
# continue and a new axes will be created
11121113
if key == ckey and isinstance(cax, projection_class):
11131114
return cax
1114-
1115-
return self.add_subplot(111, **kwargs)
1115+
1116+
# no axes found, so create one which spans the figure
1117+
return self.add_subplot(1, 1, 1, **kwargs)
11161118

11171119
def sca(self, a):
11181120
'Set the current axes to be a and return a'
@@ -1395,7 +1397,6 @@ def tight_layout(self, renderer=None, pad=1.08, h_pad=None, w_pad=None, rect=Non
13951397
self.subplots_adjust(**kwargs)
13961398

13971399

1398-
13991400
def figaspect(arg):
14001401
"""
14011402
Create a figure with specified aspect ratio. If *arg* is a number,

lib/matplotlib/pyplot.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,12 +2087,8 @@ def polar(*args, **kwargs):
20872087
Multiple *theta*, *r* arguments are supported, with format
20882088
strings, as in :func:`~matplotlib.pyplot.plot`.
20892089
2090-
An optional kwarg *resolution* sets the number of vertices to
2091-
interpolate between each pair of points. The default is 1,
2092-
which disables interpolation.
20932090
"""
2094-
resolution = kwargs.pop('resolution', 1)
2095-
ax = gca(polar=True, resolution=resolution)
2091+
ax = gca(polar=True)
20962092
ret = ax.plot(*args, **kwargs)
20972093
draw_if_interactive()
20982094
return ret

lib/matplotlib/tests/test_axes.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
from numpy import ma
33
import matplotlib
4-
from matplotlib.testing.decorators import image_comparison, knownfailureif
4+
from matplotlib.testing.decorators import image_comparison, cleanup
55
import matplotlib.pyplot as plt
66

77

@@ -733,6 +733,7 @@ def test_scatter_plot():
733733
ax = plt.axes()
734734
ax.scatter([3, 4, 2, 6], [2, 5, 2, 3], c=['r', 'y', 'b', 'lime'], s=[24, 15, 19, 29])
735735

736+
@cleanup
736737
def test_as_mpl_axes_api():
737738
# tests the _as_mpl_axes api
738739
from matplotlib.projections.polar import PolarAxes
@@ -755,9 +756,7 @@ def _as_mpl_axes(self):
755756
assert type(ax) == PolarAxes, \
756757
'Expected a PolarAxes, got %s' % type(ax)
757758
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
761760
plt.close()
762761

763762
# testing axes creation with gca

lib/matplotlib/tests/test_figure.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
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
44
import matplotlib.pyplot as plt
55

66

@@ -38,3 +38,30 @@ def test_figure():
3838
# Return to the original; make sure the red line is not there.
3939
plt.figure('today')
4040
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+

0 commit comments

Comments
 (0)
0