Kamanda commited on
Commit
bb9bfdc
1 Parent(s): ab8e8da

first commit

Browse files
Files changed (2) hide show
  1. matplotlib_gradio_plot.py +39 -0
  2. requirements.txt +5 -0
matplotlib_gradio_plot.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from math import log
3
+ import matplotlib
4
+ matplotlib.use('Agg')
5
+ import matplotlib.pyplot as plt
6
+ import numpy as np
7
+ import pandas as pd
8
+
9
+
10
+ def gdp_change(r, year, country, smoothen):
11
+ years = ['1850', '1900', '1950', '2000', '2050']
12
+ m = years.index(year)
13
+ start_day = 10* m
14
+ final_day = 10* (m + 1)
15
+ x = np.arange(start_day, final_day + 1)
16
+ pop_count = {"USA": 350, "Canada": 40, "Mexico": 300, "UK": 120}
17
+ if smoothen:
18
+ r = log(r)
19
+ df = pd.DataFrame({'day': x})
20
+ df[country] = ( x ** (r) * (pop_count[country] + 1))
21
+ fig = plt.figure()
22
+ plt.plot(df['day'], df[country].to_numpy(), label = country)
23
+ plt.title("GDP in " + year)
24
+ plt.ylabel("GDP (Millions)")
25
+ plt.xlabel("Population Change since 1800")
26
+ plt.grid()
27
+ return fig
28
+
29
+ inputs = [
30
+ gr.Slider(1, 4, 3.2, label="R"),
31
+ gr.Dropdown(['1850', '1900', '1950', '2000', '2050'], label="Year"),
32
+ gr.Radio(["USA", "Canada", "Mexico", "UK"], label="Countries", ),
33
+ gr.Checkbox(label="Log of GDP Growth Rate?"),
34
+ ]
35
+ outputs = gr.Plot()
36
+
37
+ demo = gr.Interface(fn=gdp_change, inputs=inputs, outputs=outputs)
38
+
39
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ gradio
2
+ math
3
+ matplotlib
4
+ numpy
5
+ pandas