So I have a small problem. I have a data set that is already present in the histogram format, so I have the center of the box and the number of events per bite. How can I now do this as a histogram I just tried to do this. >
cans, n = hist () but it did not like it. Any recommendations?
import matplotlib.pyplot as plt import nppy as np mu, sigma = 100, 15x = mu + sigma * np.random.randn (10000) hist, bins = npi histogram (x, beans = 50) width = 0.7 * (cans [1] - cans [0]) center = (cans [ -1] + bins [1:] / 2 plt.bar (center, hist, align = 'center', width = width) plt.show ()
The object-oriented interface is also straightforward:
Fig, Ax = bar (center, hist, align = 'center', width = width) fig.savefig ("1.png") If you are using custom (non-continuous) compartments, you can calculate the width using np.diff , from the width to ax.bar You can pass and use the ax.set_xticks : import label matplotlib.pyplot such as plt import nppy np mu to label bin edges In form, sigma = 100, 15x = mu + sigma * np .random.randn (10000) bins = [0, 40, 60, 75, 90, 110, 125, 140, 160, 200] Hist, debings = NP. Astrogram (X, bins = bins) width = NPDIFIF (cans) center = (cans [: - 1] + cans [1:]) / 2 fig, ax = PLT. Subplots (figs = (8,3)) ax. Bar (center, hist, align = 'center', width = width) ax.sset_xticks (cans) Fig.savefig ("/ tmp / out.png") plt.show () < P>
Comments
Post a Comment