Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Axes3d error on set_title #1759

Closed
janrito opened this Issue · 5 comments

3 participants

@janrito

The Axes3D calls set_title with an empty loc parameter, which throws an error.

/usr/local/lib/python2.7/dist-packages/mpl_toolkits/mplot3d/axes3d.pyc in set_title(self, label, fontdict, **kwargs)
   2362 
   2363     def set_title(self, label, fontdict=None, **kwargs):
-> 2364         Axes.set_title(self, label, fontdict, **kwargs)
   2365         (x, y) = self.title.get_position()
   2366         self.title.set_y(0.92 * y)

/usr/local/lib/python2.7/dist-packages/matplotlib/axes.pyc in set_title(self, label, loc, fontdict, **kwargs)
   3216             title = {'left': self._left_title,
   3217                      'center': self.title,
-> 3218                      'right': self._right_title}[loc.lower()]
   3219         except KeyError:
   3220             raise ValueError("'%s' is not a valid location" % loc)

AttributeError: 'NoneType' object has no attribute 'lower'

If the loc parameter is passed explicitly to set_title:

p, ax = plt.subplots(subplot_kw={'projection': '3d'})
ax.set_title('Title', loc='center')

the loc parameter is passed twice, and the following error occurs:

/usr/local/lib/python2.7/dist-packages/mpl_toolkits/mplot3d/axes3d.pyc in set_title(self, label, fontdict, **kwargs)
   2362 
   2363     def set_title(self, label, fontdict=None, **kwargs):
-> 2364         Axes.set_title(self, label, fontdict, **kwargs)
   2365         (x, y) = self.title.get_position()
   2366         self.title.set_y(0.92 * y)

TypeError: set_title() got multiple values for keyword argument 'loc'
@WeatherGod
Collaborator

Looks like this is a regression in master only. Possibly caused by the recent changes to set_title()? I am not exactly sure what is happening here, but it isn't caused by Axes3D, so this is a release-blocker.

@efiring
Owner

The problem is that Axes3D is calling Axes.set_title with fontdict as a positional argument, not a kwarg, so it is being mis-interpreted as loc, because that is now the third argument in Axes.set_title. I think that if you change line 2364 to use "fontdict=fontdict", everything will work.

@WeatherGod
Collaborator
@efiring
Owner

Changing the relative positions of the named kwargs in set_title is a reasonable thing to do, given the history of it. You could make that change in the same PR; now is the time to change it, since there has been no release with the loc kwarg in set_title.

I think the rationale for having loc come before fontdict is that it is a more natural to be able to write "ax.set_title('some title', 'left')', leaving out the loc keyword, than to do that with the fontdict, which is a complex beast. That has to be weighed against the possibility of breakage, given the long history of set_title with the fontdict kwarg following the string argument.

@WeatherGod
Collaborator
@HubertHolin HubertHolin referenced this issue from a commit in HubertHolin/matplotlib
@WeatherGod WeatherGod Make loc come after fontdict in set_title. Closes #1759 bf9af44
@HubertHolin HubertHolin referenced this issue from a commit in HubertHolin/matplotlib
@WeatherGod WeatherGod Make loc come after fontdict in set_title. Closes #1759 c4bf2a1
@HubertHolin HubertHolin referenced this issue from a commit in HubertHolin/matplotlib
@WeatherGod WeatherGod Make loc come after fontdict in set_title. Closes #1759 710eb4d
@HubertHolin HubertHolin referenced this issue from a commit in HubertHolin/matplotlib
@WeatherGod WeatherGod Make loc come after fontdict in set_title. Closes #1759 e397aeb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.