2017-01-12 1 views
1

Ich versuche, die Gauß-Funktion mit Matplotlib plotten. Dies ist mein Code:Gauss-Funktion Python

#!/usr/bin/env python 
    from matplotlib import pyplot as plt 
    import numpy as np 
    import math 

    def gaussian(x, alpha, r): 
      return 1./(math.sqrt(alpha**math.pi))*np.exp(-alpha*np.power((x - r), 2.)) 

    x = np.linspace(-3, 3, 100) 
    plt.plot(gaussian(x, 1, 0)) 

    plt.show() 

Warum der Bereich von 0 bis 100 ist stattdessen zwischen -3 und 3 zu sein? enter image description here

Antwort

2
  • plot (y): plot y unter Verwendung von x als Index-Array 0..N-1
  • plot (x, y): plot x und y unter Verwendung von Standard-Linienarten und Farben

ändern plt.plot(gaussian(x, 1, 0))-plt.plot(x, gaussian(x, 1, 0))

Ausgang:

enter image description here

+0

Super! Vielen Dank! – Monica