In [1]:
%matplotlib notebook
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

In [2]:
data=pd.read_csv("05_temp_rain_v2.csv")
#data.columns
#data

In [5]:
pivot=data.pivot_table(["rain(mm)","temp(dC)"], index=["loc","month"])#.plot()
pivot.head()


Out[5]:
rain(mm) temp(dC)
loc month
Adria_-_Bellombra 1 41.314286 2.933333
2 41.552381 4.280952
3 49.152381 8.733333
4 60.342857 13.038095
5 67.590476 18.185714

In [25]:
pivot=data.pivot_table(["rain(mm)","temp(dC)"], index=["loc","month"])#.plot()
pivot

#pivot.xs("Agna", level=0)
locations=pivot.index.get_level_values(0).unique()
print(locations)
months=pivot.index.get_level_values(1).unique()
print(months)

for location in locations:
    #print(pivot.xs(location, level=0))
    split=pivot.xs(location)
    print(split)
    #split.plot()
    #break
    rain=list(split["rain(mm)"])#.plot(kind="bar")
    temp=list(split["temp(dC)"])#.plot()
    #print("printing rain")
    #print(rain)
    #print("printing temp")
    #print(temp)    
    #rain.plot(kind="bar")
    #temp.plot()
    
    i = np.arange(len(rain))
    fig, rr = plt.subplots()

    #bar_width = 1

    opacity = 0.4
    #error_config = {'ecolor': '0.3'}


    rr.bar(i, rain, alpha=opacity, color='b',
                  align='center' )

    tt=plt.twinx()
    tt.plot(temp, linestyle='-', color="r", linewidth=1.0, label="temp")

    plt.xlabel('months')
    rr.set_ylabel('(mm)')
    #plt.ylabel('(mm)')
    tt.set_ylabel('(C)')
    text="rain and temp of " + location
    plt.title(text)
    plt.xticks(i,('jan', 'feb', 'mar', 'apr', 'mai', 'jun', 'jul', 'aug', 'sept', 'oct', 'nov', 'dez'))
    plt.legend()
    plt.grid(True)


    #rr.set_ylim([0,40])
    plt.tight_layout()
    plt.show()
    
        
    #rain=pivot.xs(location, level=0)["rain(mm)"]
    #temp=pivot.xs(location, level=0)["temp(dC)"]
    #print(rain)
    #rain.plot(kind="bar")
    #temp.plot()
    #plt.show()


['Adria_-_Bellombra' 'Agna' 'Agordo']
[ 1  2  3  4  5  6  7  8  9 10 11 12]
        rain(mm)   temp(dC)
month                      
1      41.314286   2.933333
2      41.552381   4.280952
3      49.152381   8.733333
4      60.342857  13.038095
5      67.590476  18.185714
6      63.828571  21.704762
7      50.085714  23.485714
8      58.809524  23.185714
9      73.076190  18.823810
10     77.047619  14.228571
11     71.009524   8.828571
12     54.780952   3.733333
        rain(mm)   temp(dC)
month                      
1      44.266667   2.823810
2      47.095238   4.223810
3      55.095238   8.657143
4      74.257143  12.885714
5      78.342857  18.042857
6      72.666667  21.800000
7      50.333333  23.700000
8      64.780952  23.204762
9      79.295238  18.609524
10     86.323810  13.933333
11     81.400000   8.614286
12     60.523810   3.680952
         rain(mm)   temp(dC)
month                       
1       78.971429  -1.809524
2       55.419048   0.180952
3       84.066667   4.852381
4      111.895238   9.095238
5      141.866667  13.576190
6      131.695238  17.028571
7      130.828571  18.733333
8      151.904762  18.171429
9      134.066667  13.923810
10     147.152381   9.304762
11     253.771429   3.709524
12      86.885714  -1.147619