How can the xticks get set from the key in a dictionary? In my original code the dictionary is empty and fills according to a data file so I can't have anything static for the xticks. Depending on what the user inputs (a number from 1-10) the graph plots from highest to lowest values of that amount but I want the user to be able to see what IP the value pertains to. The keys are IP addresses so the ticks will also have to be vertical since they take up a fair amount of space. Thanks
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 = np.arange(1,len(y)+1,1)
fig, ax = plt.subplots()
ax.bar(x,y,align='center', width=0.2, color = 'g')
ax.set_xticks(x)
ax.set_xlabel("This graph shows amount of protocols used")
ax.set_ylabel("Number of times used")
ax.grid('on')
else:
print ("\nThere are not enough domains for this top amount.")