Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
wants to merge 16 commits into from
Prev Previous commit
Next Next commit
Fixed error messages substitution.
  • Loading branch information
Phil Elson committed Feb 6, 2012
commit eb37499b3f005da393778a3b6deaf8ca32a892f6
21 changes: 10 additions & 11 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,8 @@ def add_axes(self, *args, **kwargs):
if ispolar:
if projection is not None and projection != 'polar':
raise ValueError(
"polar=True, yet projection='%s'. " +
"Only one of these arguments should be supplied." %
projection)
"polar=True, yet projection='%s'. " % projection +
"Only one of these arguments should be supplied.")
projection = 'polar'

if isinstance(projection, basestring) or projection is None:
Expand All @@ -708,7 +707,8 @@ def add_axes(self, *args, **kwargs):
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)
TypeError('projection must be a string, None or implement a '
'_as_mpl_axes method. Got %r' % projection)

a = projection_factory(projection, self, rect, **kwargs)

Expand Down Expand Up @@ -762,9 +762,8 @@ def add_subplot(self, *args, **kwargs):
if ispolar:
if projection is not None:
raise ValueError(
"polar=True, yet projection=%r. " +
"Only one of these arguments should be supplied." %
projection)
"polar=True, yet projection=%r. " % projection +
"Only one of these arguments should be supplied.")
projection = 'polar'

if isinstance(projection, basestring) or projection is None:
Expand All @@ -773,7 +772,8 @@ def add_subplot(self, *args, **kwargs):
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)
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)
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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.

Expand Down Expand Up @@ -1058,9 +1058,8 @@ def gca(self, **kwargs):
if ispolar:
if projection is not None and projection != 'polar':
raise ValueError(
"polar=True, yet projection='%s'. " +
"Only one of these arguments should be supplied." %
projection)
"polar=True, yet projection='%s'. " % projection +
"Only one of these arguments should be supplied.")
projection = 'polar'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No "_as_mpl_axes" code here? Believe it or not, but many users use "fig.gca()" as shorthand for "fig.add_axes()" or "fig.add_subplot(111)".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot Ben. I have factored out the commonality between add_axes/add_subplot/gca which will make my changes a little noisy. I will be adding the commit shortly.

projection_class = get_projection_class(projection)
Expand Down