-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Non string projection definitions #694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
1a0021b
ab0615c
756dd8c
40a0ec9
53cbea6
bd0fd6e
eb37499
1fa7d39
89053c5
7674dcd
f8021a2
677a0ed
836a459
564e042
270f291
597b6f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -702,8 +702,16 @@ def add_axes(self, *args, **kwargs): | |
| projection) | ||
| projection = 'polar' | ||
|
|
||
| if isinstance(projection, basestring) or projection is None: | ||
| projection_class = get_projection_class(projection) | ||
| elif hasattr(projection, '_as_mpl_axes'): | ||
| projection_class, extra_kwargs = projection._as_mpl_axes() | ||
| kwargs.update(**extra_kwargs) | ||
| else: | ||
| TypeError('projection must be a string, None or implement a _as_mpl_axes method. Got %r' % projection) | ||
|
|
||
| a = projection_factory(projection, self, rect, **kwargs) | ||
|
|
||
| self._axstack.add(key, a) | ||
| self.sca(a) | ||
| return a | ||
|
|
@@ -714,10 +722,11 @@ def add_subplot(self, *args, **kwargs): | |
| Add a subplot. Examples: | ||
|
|
||
| fig.add_subplot(111) | ||
| fig.add_subplot(1,1,1) # equivalent but more general | ||
| fig.add_subplot(212, axisbg='r') # add subplot with red background | ||
| fig.add_subplot(111, polar=True) # add a polar subplot | ||
| fig.add_subplot(sub) # add Subplot instance sub | ||
| fig.add_subplot(1,1,1) # equivalent but more general | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines exceed 75 characters wide. Please follow PEP 8. |
||
| fig.add_subplot(212, axisbg='r') # add subplot with red background | ||
| fig.add_subplot(111, projection='polar') # add a polar subplot | ||
| fig.add_subplot(111, polar=True) # add a polar subplot | ||
| fig.add_subplot(sub) # add Subplot instance sub | ||
|
|
||
| *kwargs* are legal :class:`!matplotlib.axes.Axes` kwargs plus | ||
| *projection*, which chooses a projection type for the axes. | ||
|
|
@@ -751,18 +760,20 @@ def add_subplot(self, *args, **kwargs): | |
| ispolar = kwargs.pop('polar', False) | ||
| projection = kwargs.pop('projection', None) | ||
| if ispolar: | ||
| if projection is not None and projection != 'polar': | ||
| if projection is not None: | ||
| raise ValueError( | ||
| "polar=True, yet projection='%s'. " + | ||
| "polar=True, yet projection=%r. " + | ||
| "Only one of these arguments should be supplied." % | ||
| projection) | ||
| projection = 'polar' | ||
|
|
||
| if isinstance(projection, basestring) or projection is None: | ||
| projection_class = get_projection_class(projection) | ||
| else: | ||
| elif hasattr(projection, '_as_mpl_axes'): | ||
| projection_class, extra_kwargs = projection._as_mpl_axes() | ||
| kwargs.update(**extra_kwargs) | ||
| else: | ||
| TypeError('projection must be a string, None or implement a _as_mpl_axes method. Got %r' % projection) | ||
|
|
||
| # Remake the key without projection kwargs: | ||
| key = self._make_key(*args, **kwargs) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Problem right here... in add_axes(), the key is made in the beginning without the extra_kwargs, but here, the key could be made with the extra kwargs, possibly preventing the ability to find an existing axes. This key making needs to be moved up to an earlier spot in the function.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but, then again, we see that there are already changes made to kwargs... must find a judicious spot for the keymaker. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,10 +56,19 @@ def get_projection_class(projection=None): | |
| if projection is None: | ||
| projection = 'rectilinear' | ||
|
|
||
| try: | ||
| return projection_registry.get_projection_class(projection) | ||
| except KeyError: | ||
| raise ValueError("Unknown projection '%s'" % projection) | ||
| if isinstance(projection, basestring): | ||
| try: | ||
| return projection_registry.get_projection_class(projection) | ||
| except KeyError: | ||
| raise ValueError("Unknown projection '%s'" % projection) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't be getting rid of a public function (even if it probably doesn't get used elsewhere) without a deprecation notice and an addendum in the api_changes. |
||
| elif hasattr(projection, '_as_mpl_axes'): | ||
| projection_class, extra_kwargs = projection._as_mpl_axes() | ||
| kwargs.update(**extra_kwargs) | ||
| else: | ||
| TypeError('projection must be a string, None or implement a _as_mpl_axes method. Got %r' % projection) | ||
|
|
||
|
|
||
|
|
||
| def projection_factory(projection, figure, rect, **kwargs): | ||
| """ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you are at it, could you add double colons here so that sphinx can render the following properly?