Reputation: 1224
I am trying to plot a histogram with mu and sigma.
Im trying to use the ec_scores values on the y axis, its supposed to show me 0.1 to 1.0 It gives me 1, 2, 3, 4, 5, 6 on the y axis instead. Im not getting any errors but this is throwing off the graph completely. Please assist me and tell me what I am doing wrong and how can i get the graph to be generated properly. Thanks.
This is my code :
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
x = np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0])
ec_scores = np.array([1., 1., 1., 0.95923677, 0.94796184, 1., 0.76669558, 1., 0.99913194, 1.])
mu, sigma = (np.mean(ec_scores), np.std(ec_scores))
fig = plt.figure()
ax = fig.add_subplot(111)
n, bins, patches = ax.hist(x, 50, normed=1, facecolor='blue', alpha=0.75)
bincenters = 0.5*(bins[1:]+bins[:-1])
y = mlab.normpdf( bincenters, mu, sigma)
l = ax.plot(bincenters, y, 'r--', linewidth=1)
ax.set_xlabel('Parameters')
ax.set_ylabel('EC scores ')
plt.plot(x, ec_scores)
ax.grid(True)
plt.show()
Currently the graph looks like this:
Upvotes: 2
Views: 510
Reputation: 6298
As mentioned by @benton in the comments, you can plot the ec_scores as a barchart:
import numpy as np
import matplotlib.pyplot as plt
x = np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0])
ec_scores = np.array([1., 1., 1., 0.95923677, 0.94796184, 1., 0.76669558, 1., 0.99913194, 1.])
mu, sigma = (np.mean(ec_scores), np.std(ec_scores))
fig = plt.figure()
ax = fig.add_subplot(111)
rects = ax.bar(x, ec_scores, width=0.1, align='center', facecolor='blue', alpha=0.75)
ax.set_xlabel('Parameters')
ax.set_ylabel('EC scores ')
ax.grid(True)
plt.show()
You can also add error bars by passing an array to the yerr
parameter. This is illustrated in the barchart example I linked to above. I am not sure what exactly you are trying to do with normpdf, but the barchart returns a list of rectangles instead of bins, so you might need to adapt this to your code.
I hope this helps.
Upvotes: 1