Python Forum

Full Version: mcerp: error while plotting a histogram
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys, python returns an error while plotting a histogram in mcerp module. I am able to plot Kernel Density Estimate plot , but plotting a histogram returns an error: TypeError: 'numpy.float64' object cannot be interpreted as an integer. I am using Python 3.6 64 bit for Windows

This is a code that returns an error:

from mcerp import *
from matplotlib import pyplot as plt
x1 = N(24,1)
x2 = N(37,4)
x4=x1*x2
x4.plot(hist=True) # if I change to x4.plot() the code works fine, but returns KDE plot only
plt.show()
Moderator Larz60+: Added python tags -- Please do this in the futue (see help: BBcode)
I installed mcerp-0.11 and tried it, it seems that it depends on ancient version of matplotlib with plt.histogram() that could accept float for number of bins.  Unfortunately mcerp doesnt specify exact dependencies and actual version of matplotlib needs bins to be integer (or list with partition), so I changed lines 260 and 660 in mcerp/__init__.py from
      h = plt.hist(vals, bins=np.round(np.sqrt(len(vals))), 
               histtype='stepfilled', normed=True, **kwargs)
to (replaced np.round with int),
      h = plt.hist(vals, bins=int(np.sqrt(len(vals))), 
               histtype='stepfilled', normed=True, **kwargs)
after that your code worked.

You have multiple options what to do:
  • try it with some old version of matplotlib (preferably in virtual env)
  • edit __init__.py but there is still problem that mcerp is few years abandoned and its possible that another problems will appear
  • use different program/package, preferably something maintained

Thanks! It worked indeed. But for some reason python referenced __init__ file in .egg archive... Anyway thank you for prompt response.