Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 mcerp: error while plotting a histogram
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.plot(hist=True) # if I change to x4.plot() the code works fine, but returns KDE plot only
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/ 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 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.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to fit a 2D histogram like in ROOT? Zandar 2 717 Aug-06-2019, 03:01 PM
Last Post: Zandar
  histogram error alyssaantarctica 1 803 Jul-09-2018, 10:46 PM
Last Post: Larz60+
  histogram with matplotlib vaugirard 10 1,805 Jun-01-2018, 04:13 AM
Last Post: vaugirard
  Help creating a histogram using an array rubadub 0 717 Apr-17-2018, 08:57 PM
Last Post: rubadub
  Histogram help dandatadan 1 880 Nov-25-2017, 06:07 AM
Last Post: heiner55
  plotting histogram vvv 1 1,438 Mar-10-2017, 11:47 PM
Last Post: zivoni

Forum Jump:

Users browsing this thread: 1 Guest(s)