Skip to content

Commit 270f291

Browse files
author
Phil Elson
committed
Review actions #3
1 parent 564e042 commit 270f291

File tree

2 files changed

+69
-32
lines changed

2 files changed

+69
-32
lines changed

doc/api/api_changes.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ For new features that were added to matplotlib, please see
1313

1414
Changes in 1.1.x
1515
================
16+
* Use of :func:`matplotlib.projections.projection_factory` is now deprecated
17+
in favour of axes class identification using
18+
:func:`matplotlib.projections.process_projection_requirements` followed by
19+
direct axes class invocation (at the time of writing, this is done by
20+
:meth:`matplotlib.figure.Figure.add_axes`,
21+
:meth:`matplotlib.figure.Figure.add_subplot` and
22+
:meth:`matplotlib.figure.Figure.gca`.
23+
This change means that third party objects can expose themselves as
24+
matplotlib axes by providing a ``_as_mpl_axes`` method (see
25+
:ref:`adding-new-scales` for more detail).
1626

1727
* Added new :class:`matplotlib.sankey.Sankey` for generating Sankey diagrams.
1828

lib/matplotlib/projections/__init__.py

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -63,40 +63,67 @@ def get_projection_class(projection=None):
6363
raise ValueError("Unknown projection '%s'" % projection)
6464

6565

66+
def projection_factory(projection, figure, rect, **kwargs):
67+
"""
68+
Get a new projection instance.
69+
70+
*projection* is a projection name.
71+
72+
*figure* is a figure to add the axes to.
73+
74+
*rect* is a :class:`~matplotlib.transforms.Bbox` object specifying
75+
the location of the axes within the figure.
76+
77+
Any other kwargs are passed along to the specific projection
78+
constructor being used.
79+
80+
.. deprecated::
81+
82+
This routine is deprecated in favour of getting the projection
83+
class directly with :func:`get_projection_class` and initialising it
84+
directly. Will be removed in version 1.3.
85+
86+
"""
87+
88+
return get_projection_class(projection)(figure, rect, **kwargs)
89+
90+
6691
def process_projection_requirements(figure, *args, **kwargs):
67-
"""
68-
Handle the args/kwargs to for add_axes/add_subplot/gca,
69-
returning::
70-
71-
(axes_proj_class, proj_class_kwargs, proj_stack_key)
72-
73-
Which can be used for new axes initialization/identification.
74-
75-
"""
76-
ispolar = kwargs.pop('polar', False)
77-
projection = kwargs.pop('projection', None)
78-
if ispolar:
79-
if projection is not None and projection != 'polar':
80-
raise ValueError(
81-
"polar=True, yet projection=%r. "
82-
"Only one of these arguments should be supplied." %
83-
projection)
84-
projection = 'polar'
85-
86-
if isinstance(projection, basestring) or projection is None:
87-
projection_class = get_projection_class(projection)
88-
elif hasattr(projection, '_as_mpl_axes'):
89-
projection_class, extra_kwargs = projection._as_mpl_axes()
90-
kwargs.update(**extra_kwargs)
91-
else:
92-
raise TypeError('projection must be a string, None or implement a '
93-
'_as_mpl_axes method. Got %r' % projection)
94-
95-
# Make the key without projection kwargs, this is used as a unique
96-
# lookup for axes instances
97-
key = figure._make_key(*args, **kwargs)
92+
"""
93+
Handle the args/kwargs to for add_axes/add_subplot/gca,
94+
returning::
95+
96+
(axes_proj_class, proj_class_kwargs, proj_stack_key)
9897
99-
return projection_class, kwargs, key
98+
Which can be used for new axes initialization/identification.
99+
100+
.. note:: **kwargs** is modified in place.
101+
102+
"""
103+
ispolar = kwargs.pop('polar', False)
104+
projection = kwargs.pop('projection', None)
105+
if ispolar:
106+
if projection is not None and projection != 'polar':
107+
raise ValueError(
108+
"polar=True, yet projection=%r. "
109+
"Only one of these arguments should be supplied." %
110+
projection)
111+
projection = 'polar'
112+
113+
if isinstance(projection, basestring) or projection is None:
114+
projection_class = get_projection_class(projection)
115+
elif hasattr(projection, '_as_mpl_axes'):
116+
projection_class, extra_kwargs = projection._as_mpl_axes()
117+
kwargs.update(**extra_kwargs)
118+
else:
119+
raise TypeError('projection must be a string, None or implement a '
120+
'_as_mpl_axes method. Got %r' % projection)
121+
122+
# Make the key without projection kwargs, this is used as a unique
123+
# lookup for axes instances
124+
key = figure._make_key(*args, **kwargs)
125+
126+
return projection_class, kwargs, key
100127

101128

102129
def get_projection_names():

0 commit comments

Comments
 (0)