1
高値から低値に並べ替える特定の値が辞書にありますが、最大1000個以上の値があります。 1から10の間の数字で、dictの上位1〜10の最高値を持つグラフの出力を与える場合、どのようにしてユーザー入力を受け取ることができますか。それは3つの最高値などをグラフ化します彼らは入力3にあれば...おかげで、高度なユーザーの入力に応じて、最高値から次の値への値のプロット方法
from collections import Counter
from scipy import *
from matplotlib.pyplot import *
import matplotlib.pyplot as plot
frequency1 = Counter({'1':100,'2':400,'3':200,'4':300,})
response1 = input("How many top domains from source? Enter a number between 1-10: ")
if response1 == "1":
if len(frequency1) >= 1:
print("\nTop 1 most is:")
for key, frequency1_value in frequency1.most_common(1):
print("\nNumber:",key,"with frequency:",frequency1_value)
########Graph for this output
x = [1,2]
y = [frequency1_value,0]
figure(1)
ax = plot.subplot(111)
ax.bar(x,y,align='center', width=0.2, color = 'm')
ax.set_xticklabels(['0', '1'])
xlabel("This graph shows amount of protocols used")
ylabel("Number of times used")
grid('on')
################################## END GRAPH
else:
print("\nThere are not enough domains for this top amount.")
if response1 == "2":
if len(frequency1) >= 2:
print("\nTop 2 most is:")
for key, frequency1_value in frequency1.most_common(2):
print("\nNumber:",key,"with frequency:",frequency1_value)
########Graph for this output
x = [1,2,3]
y = [frequency1_value,frequency1_value,0]
figure(1)
ax = plot.subplot(111)
ax.bar(x,y,align='center', width=0.2, color = 'm')
ax.set_xticklabels(['0', '1','','2'])
xlabel("This graph shows amount of protocols used")
ylabel("Number of times used")
grid('on')
################################## END GRAPH
else:
print("\nThere are not enough domains for this top amount.")
ありがとう!これはpython 3.5で動作しますか? 19行目にstr()> int()というエラーが出ます。 – k5man001
実際には、私はそれを得ました、入力はintにキャストする必要がありました..あなたの助けをありがとう! – k5man001