这是需要在条形图中获取的一小部分数据,以及我尝试使用的代码。但是括号和括号内的“,”而不是“:”,使我知道如何完成这项工作在任何方面都是不可能的。(我想制作一个条形图,显示链接显示的时间,如:'http://www.wikidata.org/entity/Q31855 5, 'http://www.wikidata.org/entity/Q5",24岁)
a_dictionary = {'class vs. total number of instances of the class': [('http://www.wikidata.org/entity/Q31855',
5),
('http://www.wikidata.org/entity/Q5', 24),
('http://www.wikidata.org/entity/Q9388534', 25)],
'property vs. total number of distinct objects in triples using the property': [('http://www.wikidata.org/prop/direct/P800',
1),
('https://w3id.org/artchives/wikidataReconciliation', 1),
('http://www.w3.org/ns/prov#wasInfluencedBy', 2),
('https://w3id.org/artchives/publicationStage', 2),
('https://w3id.org/artchives/hasSecondLink', 2)]}
keys = a_dictionary.keys()
values = a_dictionary.values()
plt.bar(keys, values)
这就是随之而来的错误:
TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U39') dtype('<U39') dtype('<U39')
有人想到用这种数据制作条形图吗
如果我使用有人在评论中建议的代码,我会得到一个错误,我认为原因是链接和数字周围的(),因为键和值之间有“,”而不是“:”。有人有解决办法吗
重新设置词典缩进的格式显示:
因此,在本例中,只有两个键及其相应的值。这些值是元组列表
绘制这样一个字典的一种方法是为每个键创建一个子图,每个子图包含元组中存在的信息的条形图
由于字符串很长,可以编写一个专用函数来拆分它们。另一个(或:附加)选项是旋转字符串
下面的代码显示了一个开始的示例:
相关问题 更多 >
编程相关推荐