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:
Ok, with the image I see it, you are using python2, so the division is truncating to integer.
This:
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.