Skip to content
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

TypeError in Axes.get_legend_handles_labels #775

Closed
wesm opened this issue Mar 19, 2012 · 4 comments · Fixed by #1107
Closed

TypeError in Axes.get_legend_handles_labels #775

wesm opened this issue Mar 19, 2012 · 4 comments · Fixed by #1107

Comments

@wesm
Copy link

wesm commented Mar 19, 2012

I had to hack this method due to a TypeError in master. No time for a pull request or unit test

    def get_legend_handles_labels(self, legend_handler_map=None):
        """
        Return handles and labels for legend

        ``ax.legend()`` is equivalent to ::

          h, l = ax.get_legend_handles_labels()
          ax.legend(h, l)

        """

        handles = []
        labels = []
        for handle in self._get_legend_handles(legend_handler_map):
            label = handle.get_label()
            #if (label is not None and label != '' and not label.startswith('_')):
            if label and not (isinstance(label, basestring) and label.startswith('_')):
                handles.append(handle)
                labels.append(label)

        return handles, labels
@mdboom
Copy link
Member

mdboom commented Mar 20, 2012

Can you provide some code to reproduce the bug? Also, this doesn't seem equivalent -- if label == '' it will be added to the legend in the new version of your code.

@wesm
Copy link
Author

wesm commented Mar 20, 2012

I'll go back and try to get you a reproduction later today. Obviously if label is not a string (for me it was an integer) then label == '' fails

@wesm
Copy link
Author

wesm commented Mar 27, 2012

Here you go:

ax = plt.gca()
ax.bar(np.arange(10), np.arange(10), label=1910)
plt.legend()

Happens if label is an integer

@dmcdougall
Copy link
Member

Fixed in #1107.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants