File size: 2,500 Bytes
524921e
 
 
 
 
 
 
 
 
 
 
aac3844
524921e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import gradio as gr

# importing necessary libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime as dt
from datetime import datetime
from pandas import Series


df = pd.read_csv("./MARUTI.csv")
data = df[['Date','Open','High','Low','Close','Volume','VWAP']]
data['Date'] = data['Date'].apply(pd.to_datetime)

df_vwap = df[['Date','VWAP']]
df_vwap['Date'] = df_vwap['Date'].apply(pd.to_datetime)
df_vwap['year'] = df_vwap.Date.dt.year
df_vwap['month'] = df_vwap.Date.dt.month
df_vwap['day'] = df_vwap.Date.dt.day
df_vwap['day of week'] = df_vwap.Date.dt.dayofweek
df_vwap.set_index('Date', inplace=True)








# fig = plt.figure()
def yearSeriesPlot():
    fig = plt.figure(figsize=(16,8))
    plt.plot(df_vwap['VWAP'], label='VWAP')
    plt.title('Time Series')
    plt.xlabel("Time(year)")
    plt.ylabel("Volume Weighted Average Price")
    plt.legend(loc='best')
    return fig

# yearly variation histogram
def yearHistogramPlot():
    fig = plt.figure(figsize=(16, 8))
    df_vwap.groupby('year')['VWAP'].mean().plot.bar()
    return fig


# monthly variations
def monthHistogramPlot():
    fig = plt.figure(figsize=(16, 8))
    df_vwap.groupby('month')['VWAP'].mean().plot.bar()
    return fig

#daily variations
def dailyHistogramPlot():
    fig = plt.figure(figsize=(16, 8))
    df_vwap.groupby('day')['VWAP'].mean().plot.bar()
    return fig

def weekDayHistogramPlot():
    fig = plt.figure(figsize=(16, 8))
    df_vwap.groupby('day of week')['VWAP'].mean().plot.bar()
    return fig
def vwapSeriesPlot():
    fig = plt.figure(figsize=(16, 8))
    df_vwap['VWAP'].plot(figsize = (10,6))
    return fig



def plotGraph(plot_type):
    if plot_type=="yearSeriesPlot":
        return yearSeriesPlot()
    elif plot_type=="yearHistogramPlot":
        return yearHistogramPlot()
    elif plot_type=="monthHistogramPlot":
        return monthHistogramPlot()
    elif plot_type=="dailyHistogramPlot":
        return dailyHistogramPlot()
    elif plot_type=="weekDayHistogramPlot":
        return weekDayHistogramPlot()
    elif plot_type=="vwapSeriesPlot":
        return vwapSeriesPlot()
    else:
        raise ValueError("select valid plot")


inputs = [
    gr.Dropdown(["yearSeriesPlot", "yearHistogramPlot", "monthHistogramPlot", "dailyHistogramPlot", "weekDayHistogramPlot", "vwapSeriesPlot"], label="Select type of plot")

]


outputs = gr.Plot()

demo = gr.Interface(
    fn=plotGraph,
    inputs=inputs,
    outputs=outputs,

)
demo.launch()