Feature request: additional arguments of hist()

Hi, I'm using matplotlib for my scientific analysis, and

    > charmed by It's function.

Thanks!

    > Because I often use another tools for data histograming, I
    > think it's convenient if matplotlib could plot already
    > histogramed data more efficiently.

This seems like the kind of thing that would best be done in your user
library. Eg, if you make a module mymatplotlib.py, you can defined
your own hist. In that file, just import matplotlib.matlab and call
matplotlib.matlab.hist within it. In fact, matplotlib.matlab.hist
calls matplotlib.mlab.hist.

On an unrelated topic:

  def hist(x, bins=10, noplot=0, normed=0, weights=, errors=)

Just wanted to point out that this is a potential gotcha in python.
For example, what do you expect the output of this code to be?

def func1(x=):
    if not len(x): x.append(1)
    print x
    
def func2(y=):
    if len(y)<2: y.append(2)
    print y

z =
func1(z)
func2(z)

The standard way to pass empty lists as default function args is to
do:

def func1(x=None):
    if x is None: x =
    #blah blah

Lists and dicts are different in this capacity than strings or ints
because the can be changed (mutable).

Thanks for your suggestions,
John Hunter

Thank you for your reply.

def func1(x=None):
    if x is None: x =
    #blah blah

The indication is right.
I should have done so. Thank you.

This seems like the kind of thing that would best be done in your user
library. Eg, if you make a module mymatplotlib.py, you can defined
your own hist. In that file, just import matplotlib.matlab and call
matplotlib.matlab.hist within it. In fact, matplotlib.matlab.hist
calls matplotlib.mlab.hist.

I am sorry that my last explanation was insufficient.
The point is that I think it is inefficient to execute the following two lines in matplotlib.mlab.hist when I know the result of "n" already.
>> n = searchsorted(sort(y), bins)
>> n = diff(concatenate([n, [len(y)]]))

For the moment, I must insert extra code
>> y = [1.0] * 1000
(and hist(y, [0.0, 2.0]) calculates n = [1000], then plot the data.)
This is very expensive.

Another point is hist() does not support error bar plot (but bar() called from hist() does support.)

So, I propose again
def hist(x, bins=10, noplot=0, normed=0, weights=None, errors=None , **kwargs):
in matplotlib.matplab.
I think if matplotlib supports this by default, it is very smart and usefull to many users when making histogram plots with matplotlib than letting hist() be mainly for the purpose of "calculating" histograms.

Example rough code.

···

------
def hist(x, bins=10, noplot=0, normed=0, weights=None, xerr=None, yerr=None, **kwargs):
    if noplot:
       if weights == None:
          return mlab.hist(x, bins, normed)
       else:
          return (weights, bins)
    else:
       try:
          if weights == None:
             ret = gca().hist(x, bins, normed)
          else:
             ret = gca().bar(bins, weights, xerr=xerr, yerr=yerr, **kwargs)
       except ValueError, msg:
          msg = raise_msg_to_str(msg)
          error_msg(msg)
          raise RuntimeError, msg
    draw_if_interactive()
    return ret