Hong-Phuc Bui
2024-09-27 45c96fe258657363ef4ad1a2ae93513ca4139e26
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
import sys
 
from matplotlib import pyplot as plt
from numint.riemann_sum import numint_epsilon
from numint.input_parser import parse_function, parse_value
 
 
def plot_cli(function_expr:str, start:str, end:str, epsilon: str):
    f = parse_function(function_expr)
 
    (a, b) = (parse_value(start), parse_value(end))
    eps = parse_value(epsilon)
    (x, y, l, r, n) = numint_epsilon(f, a, b, eps)
    fig, ax = plt.subplots()
    ax.stairs(y[1:], x, baseline=0, fill=True, alpha=1,label=function_expr)
    ax.stairs(y[0:-1], x, baseline=0, fill=True, color="orange", alpha=0.5, label=function_expr)
    #ax.step(x, y, label=function_expr)
    #ax.step(x, y, where="post", label=function_expr)
 
    ax.plot(x, y, color="black")
 
    plt.show()
    pass
 
 
def main():
    function_expr = sys.argv[1]
    start = sys.argv[2]
    end = sys.argv[3]
    eps = sys.argv[4]
    plot_cli(function_expr, start, end, eps)
 
 
if __name__ == "__main__":
    main()