| | |
Plotting math functions (Python)
VPython's fame is with 3D animated modeling, but it's plotting abilities, while not flashy, are easy to understand and very useful. This program uses VPython to plot math functions y = sin(x) and y = cos(x) and y = sin(x)*cos(x).
# simple plotting with VPython from http://vpython.org # for the Windows version and Python24 download: VPython-Win-Py2.4-3.2.3b.exe # tested with Python24 vegaseat 01sep2005 str1 = "blue is sin(x), red is cos(x), green is sin(x)*cos(x)" import visual.graph as vg # set up the plot display, if xmax,xmin,ymax,ymin are not specified then default is autoscale graph1 = vg.gdisplay(x=0, y=0, width=600, height=350, title = str1, xtitle='x', ytitle='y', xmax=5.0, xmin=-5.0, ymax=1.1, ymin=-1.1, foreground=vg.color.black, background=vg.color.white) # gcurve() draws a line y1 = vg.gcurve(color=vg.color.blue) y2 = vg.gcurve(color=vg.color.red) y3 = vg.gcurve(color=vg.color.green) # arange() is like range() with floating point values for x in vg.arange(-5, 5, 0.1): y1.plot( pos=(x, vg.sin(x)) ) y2.plot( pos=(x, vg.cos(x)) ) y3.plot( pos=(x, vg.sin(x)*vg.cos(x)) )
Similar Threads
- <math.h> functions (C++)
- calling python functions from cpp functions. (Python)
- Math Functions (C++)
- Code Snippet: Plotting math functions (C)
- Finding the Big Oh for these Math.functions (Computer Science)
| Thread Tools | Search this Thread |
abrupt alarm ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog cx-freeze data decimals dictionaries dictionary directory dynamic error examples exe file float format function gnu graphics gui halp heads homework http ideas import input java launcher leftmouse line linux list lists loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext sqlite statistics string strings sudokusolver sum table terminal text thread threading time tlapse tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable ventrilo wikipedia write wxpython xlib



