import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import datetime
from datetime import date
import seaborn as sns
import calendar
import matplotlib.dates as mdates


data = pd.read_excel(r'C:\Users\stani\Desktop\Webapp\st_zagora\data_for_python2.xlsx') 
df = pd.DataFrame(data)
df['data'] = pd.to_datetime(df['data']).dt.date
df['year'] = pd.DatetimeIndex(df['data']).year

#year=2019
#df[(df['year'] == year)] tova e vajno
 
choice_value=[2019, 2020]
df1=df[df['year'].isin(choice_value)]

#df['year_unique'] = df['year'].unique()
#year_float=df['year'].unique()
#year=list(map(str,year_float))

#df.loc[(df['year'] == 2019)] 
#st.write('You selected:', df['data'])
#year=2019
#df[(df['year'] == year)]

#measurements= df['total_income']

#st.sidebar.markdown("### Histogram: Explore Distribution of Measurements : ")

#hist_axis = st.sidebar.multiselect(label="Histogram Ingredient", options=measurements, default=["mean radius", "mean texture"])
    
fig, ax = plt.subplots(figsize=(15,8))
x = np.arange(len(df1))
ax.autoscale()
    #print (x)
year_month_formatter = mdates.DateFormatter("%b") # four digits for year, two for month
half_year_locator = mdates.MonthLocator(interval=3)
ax.xaxis.set_major_locator(half_year_locator)
ax.xaxis.set_major_formatter(year_month_formatter) # formatter for major axis only

width = 0.4
plt.bar(df1['data'], df1['total_income'],
        width+0.5, color='tab:green', label='income')
plt.bar(df1['data'], df1['total_expenses'], 
        width, color='red', label='expenses')
#plt.plot(df['data'], df_['total income'], color='black')
#    df['data'].plot(kind='bar', color='red')
#$    df['data'].plot(kind='line', marker='*', color='black', ms=10)
##ax.plot(
        #ax.get_xticks(),
       #df[['col1', 'col2']].values
      # df2[['col2']].values,
 #      df['profit_mount'].values,
  #     linestyle='-',
   #    marker='o', linewidth=2.0)

#ax.plot(df['profit_mount'], linestyle = 'dotted')
 
plt.plot(df1['data'], df1['profit_mount'], linestyle='--', marker='o', label="profit")
plt.title('Income from milk in farm', fontsize=25)
plt.xlabel('Months', fontsize=20)
plt.xticks( fontsize=17)
#plt.axhline(df['profit_mount'], color='red', linestyle='--', linewidth=3, label='Average')
plt.ylabel('Lev', fontsize=20)
plt.yticks(fontsize=17)
sns.despine(bottom=True)
ax.grid(False)
ax.tick_params(bottom=False, left=True)
plt.legend(frameon=False,fontsize=15)
    #plt.show()
st.pyplot(fig)