Python中文
首页
教程
问答
标签
搜索
登录
注册
如何在Python的matplotlib中绘制cdf?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我有一个名为<code>d</code>的无序列表,看起来像:</p> <pre><code>[0.0000, 123.9877,0.0000,9870.9876, ...] </code></pre> <p>我只想使用Python中的Matplotlib基于这个列表绘制一个cdf图。但不知道我能不能用</p> <pre><code>d = [] d_sorted = [] for line in fd.readlines(): (addr, videoid, userag, usertp, timeinterval) = line.split() d.<a href="https://www.cnpython.com/list/append" class="inner-link">append</a>(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) </code></pre> <p>现在我正在使用此代码,但错误消息是:</p> <pre><code>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) </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>计算累积和<code>cumsum</code>的numpy函数在这里很有用</p> <pre><code>In [1]: from numpy import cumsum In [2]: cumsum([.2, .2, .2, .2, .2]) Out[2]: array([ 0.2, 0.4, 0.6, 0.8, 1. ]) </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
无法使用Django/mongoengine连接到MongoDB(身份验证失败)
1 回答
无法使用Django\u mssql\u后端迁移到外部hos
2 回答
无法使用Django&Python3.4连接到MySql
1 回答
无法使用Django+nginx上载媒体文件
8 回答
无法使用Django1.6导入名称模式
1 回答
无法使用Django1.7和mongodb登录管理站点
6 回答
无法使用Djangoadmin创建项目,进程使用了错误的路径,因为我事先安装了错误的Python
2 回答
无法使用Djangockedi验证CBV中的字段
8 回答
无法使用Djangocketditor上载图像(错误400)
2 回答
无法使用Djangocron进行函数调用
9 回答
无法使用Djangofiler djang上载文件
6 回答
无法使用Djangokronos
4 回答
无法使用Djangomssql provid
5 回答
无法使用Djangomssql连接到带有Django 1.11的MS SQL Server 2016
6 回答
无法使用Djangomssq迁移Django数据库
7 回答
无法使用Djangonox创建用户
8 回答
无法使用Djangopyodb从Django查询SQL Server
8 回答
无法使用Djangopython3ldap连接到ldap
1 回答
无法使用Djangoredis连接到redis
2 回答
无法使用Django中的FK创建新表
9 回答