如何用Python3中的pylab消除xaxis标签中的混乱/重叠?

2024-05-28 19:30:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我们在d中保存了以下OrderedDictionary:

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)给出{}

我们绘制如下:

^{pr2}$

结果图

resulting plot

我们希望消除x轴标签之间的重叠。或者,有没有更好的方法来绘制这本词典?在


Tags: 绘制catordereddictgwbaidumcafeeprotnod32
1条回答
网友
1楼 · 发布于 2024-05-28 19:30:07

设置图形大小,并使用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

相关问题 更多 >

    热门问题