Hakureirm commited on
Commit
5801ff5
·
verified ·
1 Parent(s): a0d4a3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -12
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import pandas as pd
3
  import numpy as np
4
- import plotly.express as px
5
 
6
  def calculate_schedule(
7
  principal: float,
@@ -65,22 +65,38 @@ def calculate_schedule(
65
  df = pd.DataFrame(schedule).round(2)
66
  df["Interest Increment (RMB)"] = df["Interest Earned (RMB)"].diff().fillna(0).round(2)
67
 
68
- # 绘图
69
- fig = px.line(
70
- df,
71
- x=display_freq,
72
- y="Future Value (RMB)",
 
 
 
 
 
73
  title=f"Compound Growth over Time ({display_freq})",
 
 
74
  template="plotly_white"
75
  )
76
- fig.update_traces(mode="lines+markers")
77
- fig.update_layout(
78
- title_font_size=20,
 
 
 
 
 
 
 
 
79
  xaxis_title=display_freq,
80
- yaxis_title="Future Value (RMB)"
 
81
  )
82
 
83
- return df, fig
84
 
85
  with gr.Blocks() as demo:
86
  gr.Markdown("## 复利计算器\n填写参数后点击“计算”查看结果")
@@ -101,6 +117,7 @@ with gr.Blocks() as demo:
101
 
102
  result_table = gr.Dataframe(interactive=False)
103
  result_plot = gr.Plot()
 
104
 
105
  compute_btn.click(
106
  fn=calculate_schedule,
@@ -109,7 +126,7 @@ with gr.Blocks() as demo:
109
  compounding, deposit_freq, display_freq,
110
  years, stop_deposit_year
111
  ],
112
- outputs=[result_table, result_plot]
113
  )
114
 
115
  demo.launch()
 
1
  import gradio as gr
2
  import pandas as pd
3
  import numpy as np
4
+ import plotly.graph_objects as go
5
 
6
  def calculate_schedule(
7
  principal: float,
 
65
  df = pd.DataFrame(schedule).round(2)
66
  df["Interest Increment (RMB)"] = df["Interest Earned (RMB)"].diff().fillna(0).round(2)
67
 
68
+ # 绘制未来价值折线图
69
+ fig_line = go.Figure()
70
+ fig_line.add_trace(go.Scatter(
71
+ x=df[display_freq],
72
+ y=df["Future Value (RMB)"],
73
+ mode='lines+markers',
74
+ name='Future Value',
75
+ line=dict(color='blue')
76
+ ))
77
+ fig_line.update_layout(
78
  title=f"Compound Growth over Time ({display_freq})",
79
+ xaxis_title=display_freq,
80
+ yaxis_title="Future Value (RMB)",
81
  template="plotly_white"
82
  )
83
+
84
+ # 绘制利息增量柱状图
85
+ fig_bar = go.Figure()
86
+ fig_bar.add_trace(go.Bar(
87
+ x=df[display_freq],
88
+ y=df["Interest Increment (RMB)"],
89
+ name='Interest Increment',
90
+ marker_color='orange'
91
+ ))
92
+ fig_bar.update_layout(
93
+ title=f"Interest Increment per {display_freq}",
94
  xaxis_title=display_freq,
95
+ yaxis_title="Interest Increment (RMB)",
96
+ template="plotly_white"
97
  )
98
 
99
+ return df, fig_line, fig_bar
100
 
101
  with gr.Blocks() as demo:
102
  gr.Markdown("## 复利计算器\n填写参数后点击“计算”查看结果")
 
117
 
118
  result_table = gr.Dataframe(interactive=False)
119
  result_plot = gr.Plot()
120
+ interest_plot = gr.Plot()
121
 
122
  compute_btn.click(
123
  fn=calculate_schedule,
 
126
  compounding, deposit_freq, display_freq,
127
  years, stop_deposit_year
128
  ],
129
+ outputs=[result_table, result_plot, interest_plot]
130
  )
131
 
132
  demo.launch()