OzoneAsai commited on
Commit
6d2862c
·
verified ·
1 Parent(s): 940b7a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -13
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import streamlit as st
2
- from sympy import symbols, solve, Eq, Ge
3
  import matplotlib.pyplot as plt
4
  import numpy as np
5
 
@@ -133,21 +133,39 @@ def inequality_solver():
133
  st.write(solution)
134
 
135
  # 不等式の解を一次元に描画
136
- plot_inequality(solution)
137
 
138
- def plot_inequality(solution):
139
- x = np.linspace(-10, 10, 400)
140
- y = np.zeros_like(x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
 
142
- plt.figure(figsize=(10, 1))
143
- plt.plot(x, y, 'k-', linewidth=1)
144
- plt.fill_between(x, y - 0.1, y + 0.1, where=(x >= solution), color='blue', alpha=0.5)
145
- plt.xlim(-10, 10)
146
- plt.ylim(-1, 1)
147
- plt.yticks([])
148
- plt.title('不等式の解のプロット')
149
 
150
- st.pyplot(plt)
151
 
152
  if __name__ == "__main__":
153
  main()
 
1
  import streamlit as st
2
+ from sympy import symbols, solve, S, Interval
3
  import matplotlib.pyplot as plt
4
  import numpy as np
5
 
 
133
  st.write(solution)
134
 
135
  # 不等式の解を一次元に描画
136
+ plot_inequality(inequality, solution)
137
 
138
+ def plot_inequality(inequality, solution):
139
+ x = symbols('x')
140
+ x_vals = np.linspace(-10, 10, 400)
141
+ y_vals = np.zeros_like(x_vals)
142
+
143
+ fig, ax = plt.subplots(figsize=(10, 2))
144
+ ax.plot(x_vals, y_vals, 'k-')
145
+
146
+ if isinstance(solution, list) and len(solution) == 2:
147
+ lower_bound, upper_bound = solution
148
+ if inequality.func == Ge:
149
+ ax.fill_between(x_vals, y_vals - 0.1, y_vals + 0.1, where=(x_vals >= lower_bound), color='blue', alpha=0.5)
150
+ elif inequality.func == Le:
151
+ ax.fill_between(x_vals, y_vals - 0.1, y_vals + 0.1, where=(x_vals <= upper_bound), color='blue', alpha=0.5)
152
+ elif isinstance(solution, Interval):
153
+ start = solution.start
154
+ end = solution.end
155
+ if solution.left_open:
156
+ start += 1e-5
157
+ if solution.right_open:
158
+ end -= 1e-5
159
+ ax.fill_between(x_vals, y_vals - 0.1, y_vals + 0.1, where=(x_vals >= start) & (x_vals <= end), color='blue', alpha=0.5)
160
+ else:
161
+ ax.fill_between(x_vals, y_vals - 0.1, y_vals + 0.1, where=(x_vals >= solution), color='blue', alpha=0.5)
162
 
163
+ ax.set_xlim(-10, 10)
164
+ ax.set_ylim(-1, 1)
165
+ ax.set_yticks([])
166
+ ax.set_title('不等式の解のプロット')
 
 
 
167
 
168
+ st.pyplot(fig)
169
 
170
  if __name__ == "__main__":
171
  main()