I have 50 measurements, which I keep in a txt file. I need a histogram. Here is my code:
f = open ( "input.txt", 'r')
a = [0] * 59
izmer = list ()
For Line In F:
a [int (int (line) / 10)] + = 1
izmer.append (int (int (line) / 10) / 10)
gist = dict ()
x = list ()
y = list ()
for i in range (0, 59):
if a [i] & gt; 0:
x.append ((i / 10))
y.append (a [i] / 50)
fig, ax = plt.subplots ()
ax.bar (x, y, width = [0.04] * len (y))
ax.set_facecolor ( 'seashell')
plt.xticks (np.arange (4, 6, 0.2))
plt.yticks (np.arange (0, 0.3,0.05))
Plt.Show ()
On top of it, I would like to draw the graph, but I do not understand how I draw it on top of the histogram. At the moment, I did two programs that feature what I need, but in different windows
Answer 1, Authority 100%
What you want to create – to construct an empirical distribution function of the density – density is called the recovery procedure on the basis of the kernel estimator (Kernel Density Estimation, KDE). There are two simple tools of its construction.
Using Seaborn.
import numpy as np
import seaborn as sns
x = np.random.normal (0,1, size = 200)
sns.distplot (x)
Using charts b-ki Pandas and Matplotlib.
import pandas as pd
Import Matplotlib.pyPlot AS PLT
fig, ax = plt.subplots ()
df = pd.DataFrame (x, columns = [[ 'A']])
df.plot.kde (ax = ax)
df.plot.hist (density = True, ax = ax)
You can also use a variety of other, more effective KDE implementations, including the SciPy (scipy.stats.gaussian_kde and scipy.signal.parzen), from Statsmodels (statsmodels.api.nonparametric) – KDEUnivariate () and KDEMultivariate () from Scikit-learn sklearn.neighbors.KernelDensity (). And then for them to build on their own schedule.