File: plotting.py

package info (click to toggle)
mpmath 1.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,356 kB
  • sloc: python: 45,321; makefile: 10
file content (37 lines) | stat: -rw-r--r-- 937 bytes parent folder | download | duplicates (4)
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
36
37
"""
Function plotting demo.
"""
from __future__ import print_function

from mpmath import *

def main():
    print("""
    Simple function plotting. You can enter one or several
    formulas, in ordinary Python syntax and using the mpmath
    function library. The variable is 'x'. So for example
    the input "sin(x/2)" (without quotation marks) defines
    a valid function.
    """)
    functions = []
    for i in xrange(10):
        if i == 0:
            s = raw_input('Enter a function: ')
        else:
            s = raw_input('Enter another function (optional): ')
        if not s:
            print()
            break
        f = eval("lambda x: " + s)
        functions.append(f)
        print("Added f(x) = " + s)
        print()
    xlim = raw_input('Enter xmin, xmax (optional): ')
    if xlim:
        xlim = eval(xlim)
    else:
        xlim = [-5, 5]
    print("Plotting...")
    plot(functions, xlim=xlim)

main()