2017-06-22 15 views
1

は、我々は、次のOrderedDictionaryはdに保存されていますPython3でpylabを使ってX軸ラベルのクラッタ/オーバーラップを除去するには?

OrderedDict([('CAT-QuickHeal', 328), 
      ('TheHacker', 328), 
      ('K7AntiVirus', 328), 
      ('F-Prot', 328), 
      ('BitDefender', 328), 
      ('ViRobot', 328), 
      ('McAfee-GW-Edition', 328), 
      ('Jiangmin', 328), 
      ('Fortinet', 328), 
      ('SUPERAntiSpyware', 328), 
      ('VBA32', 328), 
      ('AVG', 328), 
      ('McAfee', 327), 
      ('Avast', 327), 
      ('ClamAV', 327), 
      ('Kaspersky', 327), 
      ('Comodo', 327), 
      ('F-Secure', 327), 
      ('DrWeb', 327), 
      ('Emsisoft', 327), 
      ('Microsoft', 327), 
      ('AhnLab-V3', 327), 
      ('nProtect', 326), 
      ('Malwarebytes', 326), 
      ('VIPRE', 326), 
      ('Symantec', 326), 
      ('NANO-Antivirus', 326), 
      ('Sophos', 326), 
      ('ESET-NOD32', 326), 
      ('GData', 326), 
      ('Panda', 326), 
      ('K7GW', 325), 
      ('MicroWorld-eScan', 324), 
      ('Ikarus', 324), 
      ('Qihoo-360', 320), 
      ('AegisLab', 319), 
      ('Rising', 319), 
      ('Ad-Aware', 319), 
      ('Kingsoft', 318), 
      ('CMC', 317), 
      ('Tencent', 316), 
      ('Cyren', 315), 
      ('Zoner', 315), 
      ('Zillya', 314), 
      ('Avira', 314), 
      ('AVware', 310), 
      ('Arcabit', 309), 
      ('ALYac', 301), 
      ('TrendMicro', 299), 
      ('Yandex', 298), 
      ('Baidu', 294), 
      ('TrendMicro-HouseCall', 288), 
      ('Bkav', 279), 
      ('Antiy-AVL', 265), 
      ('Not Detected', 264), 
      ('Invincea', 250), 
      ('TotalDefense', 250), 
      ('CrowdStrike', 239), 
      ('Webroot', 219), 
      ('ZoneAlarm', 216), 
      ('Endgame', 192), 
      ('Paloalto', 176), 
      ('SentinelOne', 171), 
      ('Alibaba', 45), 
      ('Baidu-International', 31), 
      ('Agnitum', 28), 
      ('ByteHero', 27), 
      ('Norman', 19), 
      ('AntiVir', 13), 
      ('Commtouch', 12), 
      ('WhiteArmor', 9), 
      ('PCTools', 7), 
      ('eSafe', 5), 
      ('VirusBuster', 2), 
      ('NOD32', 2), 
      ('eTrust-Vet', 2), 
      ('Prevx', 2), 
      ('Avast5', 2), 
      ('SymantecMobileInsight', 1), 
      ('Authentium', 1), 
      ('Sunbelt', 1)]) 

type(d)は、次のように我々はそれをプロットcollections.OrderedDict

います:

dictlist = [] 
for key, value in d.items(): 
    temp = [key,value] 
    dictlist.append(temp) 

x = []; y = [] 
for pair in dictlist: 
    x.append(pair[0]) 
    y.append(pair[1]) 
r = range(81) 
pl.xticks(r, x) 
pl.xticks(r, x, rotation=90) 
pl.plot(r,y,'*') 
pl.show() 

結果のプロット

resulting plot

x軸ラベルの重なりを取り除きたい。あるいは、この辞書をプロットする良い方法はありますか?

答えて

0

図のサイズを設定し、プロットを良くするためにtight_layout()も使用してください。 d.keysとd.valuesを使用してキーと値を取得できます。

import matplotlib.pyplot as pl 
pl.figure(num=None, figsize=(10, 6), dpi=80, facecolor='w', edgecolor='k') 
pl.bar(range(len(d.keys())), d.values()) 
pl.xticks(range(len(d.values())), d.keys(), rotation=90) 
pl.tight_layout() 
pl.show() 

はありがとう

enter image description here

+0

になります。それは動作します。 1つ最後のこと:このグラフではポイントやティックの代わりにバーラインを生成する方法はありますか?たとえば、x-label = CAT-Quickhealの上に横棒線があり、Y軸上で328になります。 – user8195347

+0

最新の編集を参照してください。 – plasmon360

関連する問題