Python Forum
histogram with matplotlib
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
histogram with matplotlib
#4
I have tried your code (copied from your post, not the one from matplotlib) and the result is the expected one: a nice histogram and a normal curve.

If you see a line that means that you have at least a correct matplotlib backend so the error must be something not so obvious. You can enter with the debugger or add some prints to the variables to understand what's happening.

Have you tried to do an easy plot:
import matplotlib.pyplot as plt

from matplotlib.patches import Rectangle

f = plt.figure()
ax = f.add_subplot(1, 1, 1)
ax.plot([1, -2, 4, -8])

r = Rectangle((0, 2), 2, 1, color='orange')
ax.add_patch(r)

plt.show()
If it does not work either I suspect it is a problem with your installation.

Ok, with the image I see it, you are using python2, so the division is truncating to integer.
This:
y = ((1 / (np.sqrt(2 * np.pi) * sigma)) *
     np.exp(-0.5 * (1 / sigma * (bins - mu))**2))
Only produces the expected result in python 3, for python 2 you need to force working with float numbers:
y = ((1.0 / (np.sqrt(2 * np.pi) * sigma)) *
     np.exp(-0.5 * (1.0 / sigma * (bins - mu))**2))
But nevertheless I recommend you to use python 3 if you are learning.
Reply


Messages In This Thread
histogram with matplotlib - by vaugirard - May-09-2018, 10:08 PM
RE: histogram with matplotlib - by scidam - May-09-2018, 11:55 PM
RE: histogram with matplotlib - by vaugirard - May-09-2018, 11:59 PM
RE: histogram with matplotlib - by killerrex - May-10-2018, 12:13 AM
RE: histogram with matplotlib - by vaugirard - May-30-2018, 09:37 PM
RE: histogram with matplotlib - by killerrex - May-30-2018, 10:16 PM
RE: histogram with matplotlib - by vaugirard - May-30-2018, 10:21 PM
RE: histogram with matplotlib - by vaugirard - May-31-2018, 04:21 AM
RE: histogram with matplotlib - by vaugirard - May-31-2018, 09:40 PM
RE: histogram with matplotlib - by snippsat - Jun-01-2018, 02:39 AM
RE: histogram with matplotlib - by vaugirard - Jun-01-2018, 04:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to fit a 2D histogram like in ROOT? Zandar 2 4,171 Aug-06-2019, 03:01 PM
Last Post: Zandar
  histogram error alyssaantarctica 1 3,790 Jul-09-2018, 10:46 PM
Last Post: Larz60+
  Plot Probability Density of an Histogram Python_TLS 1 2,906 Jun-28-2018, 06:19 AM
Last Post: scidam
  Help creating a histogram using an array rubadub 0 2,202 Apr-17-2018, 08:57 PM
Last Post: rubadub
  Histogram help dandatadan 1 2,575 Nov-25-2017, 06:07 AM
Last Post: heiner55
  mcerp: error while plotting a histogram rakhmadiev 2 4,571 Apr-02-2017, 09:08 PM
Last Post: rakhmadiev
  plotting histogram vvv 1 3,326 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