Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: histogram() got an unexpected keyword argument 'new'

I'm having a hard time trying to plot histograms using python, numpy and matplotlib on a mac osx. I had this working perfectly 6 months ago however the same code produces this error:

In [1]: %matplotlib inline

In [2]:import numpy as np
       from numpy.random import randn
       import pandas as pd
       import matplotlib as mpl
       import matplotlib.pyplot as plt
       from scipy import stats

       data = randn(75)
       plt.hist(data)

Returns the following message:

    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-2-fa104aadeee7> in <module>()
      8 
      9 data = randn(75)
---> 10 plt.hist(data,bins=20, density=True)

     /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/pyplot.pyc in hist(x, bins, range, normed, weights, cumulative, bottom,  histtype, align, orientation, rwidth, log, color, label, hold, **kwargs)
   2339         ax.hold(hold)
   2340     try:
-> 2341         ret = ax.hist(x, bins, range, normed, weights, cumulative,  bottom,     histtype, align, orientation, rwidth, log, color, label, **kwargs)
   2342         draw_if_interactive()
   2343     finally:

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.pyc in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, **kwargs)
   7734             # this will automatically overwrite bins,
   7735             # so that each histogram uses the same bins
-> 7736             m, bins = np.histogram(x[i], bins, weights=w[i],     **hist_kwargs)
   7737             if normed:
   7738                 db = np.diff(bins)

TypeError: histogram() got an unexpected keyword argument 'new''

I have attempted to uninstall and reinstall python, ipython, numpy, matplotlib and scipy and install them in /usr/local/bin though the error persists.

Has anyone seen this issue before or would know a possible solution? Thanks

like image 630
Rob Scott Avatar asked Apr 24 '15 08:04

Rob Scott


1 Answers

For me the comment from cphlewis was the hint I needed. I was working with matplotlib 1.1, and after an update to 1.5 everything works fine for me.

like image 102
meltdown90 Avatar answered Oct 07 '22 22:10

meltdown90