Ho un elenco disordinato di nome d
che assomiglia:Come plottare cdf in matplotlib in Python?
[0.0000, 123.9877,0.0000,9870.9876, ...]
ho semplicemente voglia di tracciare un grafico CDF sulla base di questo elenco utilizzando Matplotlib in Python. Ma non so se c'è una funzione posso usare
d = []
d_sorted = []
for line in fd.readlines():
(addr, videoid, userag, usertp, timeinterval) = line.split()
d.append(float(timeinterval))
d_sorted = sorted(d)
class discrete_cdf:
def __init__(data):
self._data = data # must be sorted
self._data_len = float(len(data))
def __call__(point):
return (len(self._data[:bisect_left(self._data, point)])/
self._data_len)
cdf = discrete_cdf(d_sorted)
xvalues = range(0, max(d_sorted))
yvalues = [cdf(point) for point in xvalues]
plt.plot(xvalues, yvalues)
Ora sto usando questo codice, ma il messaggio di errore è:
Traceback (most recent call last):
File "hitratioparea_0117.py", line 43, in <module>
cdf = discrete_cdf(d_sorted)
TypeError: __init__() takes exactly 1 argument (2 given)
Come quello [mostrato qui] (http://matplotlib.sourceforge.net/examples/pylab_examples/histogram_demo_extended.html) (3a figura)? – chl
@chl sì, qualcosa del genere – manxing
Il tuo errore '__init __() richiede esattamente 1 argomento (2 dato)' deriva dal fatto che il tuo metodo di classe '__init__' dovrebbe prendere in sé' def __init __ (self, data) '. – Hooked