Tenebris Mortem
Tenebris Mortem

Reputation: 93

Creating Spaces for matplotlib graphs

I'm task to make a graph based on a total rainfall per month I did the code and the graph but I have a problem in X axis it does not have enough space for it to be readable. I thought giving the x axis a bigger value will help but I guess i'm wrong

code:

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()

output:

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

graph:

Line Graph for rainfall per month

Upvotes: 1

Views: 49

Answers (1)

Sheldore
Sheldore

Reputation: 39072

Try rotating the tick labels by 90 degrees using rotation=90

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"], rotation=90)

Upvotes: 1

Related Questions