Skip to content

Commit e52f25d

Browse files
committed
improved visualization
1 parent 417f563 commit e52f25d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

numerical_integration_app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,16 @@ def f(x):
7979
# Plot the function and highlight the area under the curve according to the limits entered
8080
x = np.linspace(a, b, n+1)
8181
y = f(x)
82+
x_actual_func = np.linspace(a, b, 500)
83+
y_actual_func = f(x_actual_func)
8284
fig, ax = plt.subplots()
83-
ax.plot(x, y, 'b', linewidth=2)
85+
ax.plot(x, y, 'b', linewidth=2, label='Trapezoidal Rule Approximation')
86+
ax.plot(x_actual_func, y_actual_func, color='brown', linestyle='dashed', linewidth=0.7, label='Actual Function')
8487
ax.fill_between(x, y, where=(x>=a)&(x<=b), color='grey', alpha=0.3)
8588
ax.set_xlabel('x')
8689
ax.set_ylabel('y')
8790
ax.set_title('Area under the curve')
91+
ax.legend(loc='upper right')
8892

8993
# Plot the sub-intervals
9094
for i in range(n):

0 commit comments

Comments
 (0)