我有一个字典如下:键 - 用户 ID 值 - 设置 2 个值 {timeTag, amount}我试图绘制一个用户(时间标签与数量),但无法弄清楚如何这样做(部分代码:import matplotlib.pyplot as pltfrom collections import defaultdic# some code adding values, for example:d = defaultdic(list)# ... some coded[userId].append({time, amount})exampleId = 150plt.plot(d[exampleId]) # give error如何绘制 userId = 150(即 exampleId 变量)与时间(x 轴)与数量(y 轴)的关系图?
1 回答

慕田峪9158850
TA贡献1794条经验 获得超7个赞
使用plt.plot
默认参数时,您需要将x
和y
值作为列表传递。所以最后一个命令将更改为
plt.plot(map(lambda userSet: userSet[0], d[exampleId]), map(lambda userSet: userSet[1], d[exampleId]))
map(lambda userSet: userSet[0], d[exampleId])
和检索到的列表的大小map(lambda userSet: userSet[1], d[exampleId])
应该相同。
添加回答
举报
0/150
提交
取消