【发布时间】:2020-05-13 16:39:20
【问题描述】:
我的任务是根据每月的总降雨量制作图表,我编写了代码和图表,但我在 X 轴上有一个问题,它没有足够的空间让它可读。 我认为给 x 轴一个更大的值会有所帮助,但我想我错了
代码:
import matplotlib.pyplot as plt
Rainfall=[0]*12
i=0
print("Enter the Rainfall each month")
while i<len(Rainfall):
print('Month #',i + 1, ': ',end=' ')
Rainfall[i]=int(input())
i+=1
total = sum(Rainfall)
ave=total/len(Rainfall)
High = max (Rainfall)
Low = min(Rainfall)
print("total Amount= ",total)
print("Average Average Amount {:0.2f}".format(ave))
print ("The months with the highest value are : ")
print ([i+1 for i, j in enumerate(Rainfall) if j == High])
print ("The months with the Lowest value are : ")
print ([i+1 for i, j in enumerate(Rainfall) if j == Low])
plt.plot([100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200],Rainfall,marker='.')
plt.xticks([100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200],['January ','Februrary','March','April','May','June','July','August','September','October',"November", "December"])
plt.xlabel('Month')
plt.ylabel('Rainfall')
plt.show()
输出:
Enter the Rainfall each month
Month # 1 : 1
Month # 2 : 2
Month # 3 : 3
Month # 4 : 4
Month # 5 : 5
Month # 6 : 6
Month # 7 : 7
Month # 8 : 8
Month # 9 : 10
Month # 10 : 12
Month # 11 : 13
Month # 12 : 14
total Amount= 85
Average Average Amount 7.08
The months with the highest value are :
[12]
The months with the Lowest value are :
[1]
Process finished with exit code 0
图表:
【问题讨论】:
标签: python matplotlib graph