python - Plotting a histogram -
i trying plot histogram mu , sigma.
im trying use ec_scores values on y axis, supposed show me 0.1 1.0 gives me 1, 2, 3, 4, 5, 6 on y axis instead. im not getting errors throwing off graph completely. please assist me , tell me doing wrong , how can graph generated properly. thanks.
this code :
import numpy np import matplotlib.pyplot plt import matplotlib.mlab 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()
as mentioned @benton in comments, can plot ec_scores barchart:
import numpy np import matplotlib.pyplot 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 add error bars passing array yerr parameter. illustrated in barchart example linked above. not sure trying normpdf, barchart returns list of rectangles instead of bins, might need adapt code.
i hope helps.


Comments
Post a Comment