GraphingWindow can be obtained by typing at the top of your brain:
from GraphingWindow import GraphingWindow
GraphingWindows are used for graphing data and visually displaying mathematical information to the user. You can open as many GraphingWindows as you want. Open one with something like:
graph = GraphingWindow(400,400,-5,10,-10,20,"MyGraph")
This will make a new window with a drawable area of 400x400, and set the coordinate frame of the window to run from x=-5 to x=10 and y=-10 to y=20. It will also title the window MyGraph. There are several methods one can now use to graph on the window:
- graph.graphContinuous(f[,color]) accepts an argument f which is a valid python function of one variable that returns a numerical value (like a one-to-one function) and graphs it as a continuous line. color is an optional second argument and is a string, default color is black. i.e. graph.graphContinuous(lambda x: x**2, "blue") will graph y=x**2 as a blue curve
- graph.graphDiscrete(f[,color]) accepts an argument f which is a valid python function of one integer variable that returns a numerical value (a discrete parameter function) and graphs it in the common visual representation of discrete functions, poles. color is an optional second argument and is a string, default color is black.
- graph.graphSlopefield(f[,color]) accepts an argument f which is a valid python function of two variables that returns a numerical value representing dy/dx (a two-to-one function, an equation for a slope field) and graphs it as a slope field. color is an optional second argument and is a string, default color is black. i.e. graph.graphSlopefield(lambda x,y: 2*x, "blue") will graph the slope field of y=x**2 (since dy/dx = 2*x for y=x**2) as a blue field. If one then right clicks at any point on the window, it will draw the solution through that point (y = x**2+C) in purple using the 4th order Range-Kutta method.
- graph.graphScalarfield(f) accepts an argument f which is a valid python function of two variable that returns a numerical value (a two-to-one function, a.k.a. a scalar field) and graphs it by mapping a color to each value and putting the appropriate color at each point. i.e. graph.graphScalarfield(lambda x,y: x*y) should give a pretty picture
You can interact with the graph with the left mouse button (by dragging it around) to change the domain being graphed. You can also change the domain being graphed by typing into the boxes at the top of the window and clicking Resize. You can also interact with the domain being graphed programatically. graph.getDomain() will return a tuple in the format ((xmin, xmax), (ymin,ymax)) and graph.setDomain((xmin, xmax), (ymin,ymax)) will change the domain to the values it is called with. i.e. to blow up the bottom-left quadrant of the graph to the whole window, use code like:
xd, yd = graph.getDomain()
graph.setDomain((xd[0], xd[0]+(xd[1]-xd[0])/2.0), (yd[0], yd[0]+(yd[1]-yd[0])/2.0))
As you graph more and more functions, they get graphed on top of one another. To clear all graphed functions from the window and just get the bare axes again, type graph.clear()
If you wish to save the current contents of the graph and write it to a postscirpt file, use the call graph.postscript("graph.ps") where graph.ps is the file it will be written to.