In [2]:
%matplotlib notebook
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
#import seaborn as sns

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

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


Out[4]:
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 [7]:
locations=pivot.index.get_level_values(0).unique()
print(locations)
months=pivot.index.get_level_values(1).unique()
print(months)
print(len(months))
#sns.set_style("ticks")


for location in locations:
    #print(pivot.xs(location, level=0))
    
    split=pivot.xs(location)
    rain=split["rain(mm)"]
    temp=split["temp(dC)"]
    #print(split)
    
    fig = plt.figure()
    ax1 = rain.plot(kind="bar")
    ax2 = ax1.twinx()
    ax2.plot(ax1.get_xticks(),temp,linestyle='-',color="r")
    #ax2.autoscale()
    
       
    ax2.set_ylim([min(temp),50])
    ax1.set_ylim([min(temp),max(rain)/0.9])
    ax1.set_ylabel('Precipitation (mm)', color='blue')
    ax2.set_ylabel('Temperature (°C)', color='red')
    ax1.set_xlabel('Months')
    
    
    plt.title(location)
    plt.tight_layout()
    
    labels = ['Jan','Feb','Mar','Apr','May','Jun', 'Jul','Aug','Sep','Oct','Nov','Dez']
    #plt.xticks(range(12),labels,rotation=45)
    ax1.set_xticklabels(labels, rotation=45)
    #sns.despine(top=True,right=False)
    #plt.savefig(location+'.svg')
    
    #-------unused----------
    #plt.autoscale()


['Adria_-_Bellombra' 'Agna' 'Agordo']
[ 1  2  3  4  5  6  7  8  9 10 11 12]
12

In [ ]: