Python Forum
mcerp: error while plotting a histogram
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
mcerp: error while plotting a histogram
#1
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)
Reply
#2
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

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to fit a 2D histogram like in ROOT? Zandar 2 4,068 Aug-06-2019, 03:01 PM
Last Post: Zandar
  histogram error alyssaantarctica 1 3,714 Jul-09-2018, 10:46 PM
Last Post: Larz60+
  Plot Probability Density of an Histogram Python_TLS 1 2,853 Jun-28-2018, 06:19 AM
Last Post: scidam
  histogram with matplotlib vaugirard 10 6,152 Jun-01-2018, 04:13 AM
Last Post: vaugirard
  Help creating a histogram using an array rubadub 0 2,159 Apr-17-2018, 08:57 PM
Last Post: rubadub
  Histogram help dandatadan 1 2,512 Nov-25-2017, 06:07 AM
Last Post: heiner55
  plotting histogram vvv 1 3,259 Mar-10-2017, 11:47 PM
Last Post: zivoni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020