Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Numeric labels do not work with plt.hist #3869

Copy link
Copy link
Closed
@mwaskom

Description

@mwaskom
Issue body actions

Many (most?) matplotlib functions accept a numeric object for the label kwarg. For example, this works fine:

x = np.random.randn(50)
plt.plot(x, label=0)
plt.legend()

foo

However, the same is not true for plt.hist:

x = np.random.randn(50)
plt.hist(x, label=0)
plt.legend()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-27407c59c8b6> in <module>()
      1 x = np.random.randn(50)
----> 2 plt.hist(x, label=0)
      3 plt.legend()

/Users/mwaskom/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.pyc in hist(x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, hold, **kwargs)
   2894                       histtype=histtype, align=align, orientation=orientation,
   2895                       rwidth=rwidth, log=log, color=color, label=label,
-> 2896                       stacked=stacked, **kwargs)
   2897         draw_if_interactive()
   2898     finally:

/Users/mwaskom/anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs)
   5858         else:
   5859             raise ValueError(
-> 5860                 'invalid label: must be string or sequence of strings')
   5861 
   5862         if len(labels) < nx:

ValueError: invalid label: must be string or sequence of strings

Is there a reason for this constraint on histogram labels?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.