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 [22]:
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=split(["temp(dC)"])#.plot()
    print("printing rain")
    print(list(rain))
    print("printing temp")
    print(list(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()
    break
        
    #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
printing rain
[41.31428571428571, 41.55238095238095, 49.152380952380952, 60.342857142857135, 67.590476190476195, 63.828571428571408, 50.085714285714296, 58.809523809523817, 73.076190476190476, 77.047619047619065, 71.009523809523799, 54.780952380952385]
printing temp
[2.9333333333333336, 4.2809523809523808, 8.7333333333333325, 13.038095238095238, 18.185714285714283, 21.704761904761902, 23.485714285714284, 23.18571428571429, 18.823809523809523, 14.228571428571431, 8.8285714285714274, 3.7333333333333329]