Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1from .. import axes, docstring, cbook 

2from .geo import AitoffAxes, HammerAxes, LambertAxes, MollweideAxes 

3from .polar import PolarAxes 

4from mpl_toolkits.mplot3d import Axes3D 

5 

6 

7class ProjectionRegistry: 

8 """A mapping of registered projection names to projection classes.""" 

9 

10 def __init__(self): 

11 self._all_projection_types = {} 

12 

13 def register(self, *projections): 

14 """Register a new set of projections.""" 

15 for projection in projections: 

16 name = projection.name 

17 self._all_projection_types[name] = projection 

18 

19 def get_projection_class(self, name): 

20 """Get a projection class from its *name*.""" 

21 return self._all_projection_types[name] 

22 

23 def get_projection_names(self): 

24 """Return the names of all projections currently registered.""" 

25 return sorted(self._all_projection_types) 

26 

27 

28projection_registry = ProjectionRegistry() 

29projection_registry.register( 

30 axes.Axes, 

31 PolarAxes, 

32 AitoffAxes, 

33 HammerAxes, 

34 LambertAxes, 

35 MollweideAxes, 

36 Axes3D, 

37) 

38 

39 

40def register_projection(cls): 

41 projection_registry.register(cls) 

42 

43 

44def get_projection_class(projection=None): 

45 """ 

46 Get a projection class from its name. 

47 

48 If *projection* is None, a standard rectilinear projection is returned. 

49 """ 

50 if projection is None: 

51 projection = 'rectilinear' 

52 

53 try: 

54 return projection_registry.get_projection_class(projection) 

55 except KeyError: 

56 raise ValueError("Unknown projection %r" % projection) 

57 

58 

59@cbook.deprecated("3.1") 

60def process_projection_requirements(figure, *args, **kwargs): 

61 return figure._process_projection_requirements(*args, **kwargs) 

62 

63 

64get_projection_names = projection_registry.get_projection_names 

65docstring.interpd.update(projection_names=get_projection_names())