如何从字典中的键设置 xticks?在我的原始代码中,字典是空的,并根据数据文件填充,所以我不能为 xticks 设置任何静态内容。根据用户输入的内容(1-10 之间的数字),图表从该金额的最高值到最低值绘制,但我希望用户能够看到该值与哪个 IP 相关。键是 IP 地址,所以刻度也必须是垂直的,因为它们占用了相当多的空间。谢谢
from collections import Counter
import matplotlib.pyplot as plt
import numpy as np
frequency2 = Counter({'205.166.231.2': 10, '205.166.231.250': 7, '205.166.231.4': 4, '98.23.108.3': 2, '205.166.231.36': 1})
vals = sorted(frequency2.values(), reverse=True)
response2 = int(input("How many top domains from source? Enter a number between 1-10: "))
if response2 > 0 and response2 < len(vals)+1:
figure(1)
y = vals[:response2]
print ("\nTop %i most domains are:" %response2)
for key, frequency2_value in frequency2.most_common(response2):
print("\nDomain IP:",key,"with frequency:",frequency2_value)
x = …
Run Code Online (Sandbox Code Playgroud)