我有一本字典如下: 密钥-用户ID 值-设置为2个值{timeTag,amount}
我想画一个用户(时间标签和数量), 但不知道怎么做(部分代码:
import matplotlib.pyplot as plt
from collections import defaultdic
# some code adding values, for example:
d = defaultdic(list)
# ... some code
d[userId].append({time, amount})
exampleId = 150
plt.plot(d[exampleId]) # give error
如何绘制userId=150(这是一个示例id变量)与时间(x轴)和数量(y轴)的关系
使用
plt.plot
时,需要传递的默认参数是x
和y
值作为列表。因此,最后一个命令将更改为由
map(lambda userSet: userSet[0], d[exampleId])
和map(lambda userSet: userSet[1], d[exampleId])
检索的列表的大小应该相同相关问题 更多 >
编程相关推荐