我有2个单独的列表,我想准备一个直方图。一个列表是要素的数量,另一个是要素的名称。计数应在y轴上,要素名称应在x轴上。
我已经准备了2个列表,并将它们组合成一个列表,然后创建了一个字典,但是当我尝试从字典中创建熊猫数据帧时,出现了错误,因此无法继续。请建议如何创建这两个列表的直方图:
feature_list = [ 'camera',
'features',
'screen',
'battery',
'iPhone',
'apps',
'Bixby',
'button',
'feature',
'pictures',
'design',
'sound',
'size',
'price',
'display',
'Camera',
'performance',
'Battery',
'bixby',
'fingerprint',
'charge',
'speed',
'charging',
'software']
feature_count = [1606,
1331,
941,
894,
579,
416,
362,
288,
209,
197,
196,
193,
183,
167,
147,
144,
143,
127,
123,
121,
114,
114,
109,
103]
zipbObj = zip(feature_list, feature_count)
dictOffeatures = dict(zipbObj)
预期结果将是这两个列表的直方图。
答案 0 :(得分:1)
我认为您正在寻找matplotlib
module,特别是bar
情节:
from matplotlib import pyplot as plt
feature_list = [ 'camera',
'features',
'screen',
'battery',
'iPhone',
'apps',
'Bixby',
'button',
'feature',
'pictures',
'design',
'sound',
'size',
'price',
'display',
'Camera',
'performance',
'Battery',
'bixby',
'fingerprint',
'charge',
'speed',
'charging',
'software']
feature_count = [1606,
1331,
941,
894,
579,
416,
362,
288,
209,
197,
196,
193,
183,
167,
147,
144,
143,
127,
123,
121,
114,
114,
109,
103]
plt.bar(feature_list, feature_count)
plt.show()
结果: