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

Skip to content

Numeric labels do not work with plt.hist #3869

Closed
@mwaskom

Description

@mwaskom

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