我与编码像这样的数据集工作:使用Python把一个元组列表成柱状图/条形图
[
[
(u'90000', 100318),
(u'21000', 58094),
(u'50000', 14695),
(u'250000', 8190),
(u'100000', 5718),
(u'40000', 4276)
]
]
我想它transmogrify成柱状图/条形图。
我一直在寻找XXX,迄今为止我试图像这样:
fig, ax = plt.subplots()
ax.yaxis.set_major_formatter(formatter)
plt.bar(x, counts)
plt.xticks(counts[0], counts[1])
plt.xticks(rotation=70)
plt.show()
然而,所产生的错误:
NameError: name 'formatter' is not defined
用于产生数据结构的代码看起来是这样的:
with open('toy_two.json', 'rb') as inpt:
dict_hash_gas = list()
for line in inpt:
resource = json.loads(line)
dict_hash_gas.append({resource['first']:resource['second']})
# Count up the values
counts = collections.Counter(v for d in dict_hash_gas for v in d.values())
counts = counts.most_common()
# Apply a threshold
threshold = 4275
counts = [list(group) for val, group in itertools.groupby(counts, lambda x: x[1] > threshold) if val]
print(counts)
而且这样的数据:
{"first":"A","second":"1","third":"2"}
{"first":"B","second":"1","third":"2"}
{"first":"C","second":"2","third":"2"}
{"first":"D","second":"3","third":"2"}
{"first":"E","second":"3","third":"2"}
{"first":"F","second":"3","third":"2"}
{"first":"G","second":"3","third":"2"}
{"first":"H","second":"4","third":"2"}
{"first":"I","second":"4","third":"2"}
{"first":"J","second":"0","third":"2"}
{"first":"K","second":"0","third":"2"}
{"first":"L","second":"0","third":"2"}
{"first":"M","second":"0","third":"2"}
{"first":"N","second":"0","third":"2"}
问题:
要清楚的问题是:如何使这个帖子开头的数据,即
[
[
(u'90000', 100318),
(u'21000', 58094),
(u'50000', 14695),
(u'250000', 8190),
(u'100000', 5718),
(u'40000', 4276)
]
]
为直方图?
x轴将是u'90000'
,u'21000'
,...,u'40000'
。
y轴将是100318
,58094
,...,4276
。
什么问题? – wwii
问题是 - 如何将该数据呈现为直方图 –
什么是'plt'?和'无花果'和'斧头'? – wwii