As with the basic DISLIN library, pxDislin contains high-level plot generating functions. Similar to the first example, creating a 2D plot in pxDislin is as simple as
>>> x=arange(100.0) >>> y = sin(x/3)+cos(x/5) >>> plot = dScatter(x,y) >>> plot.add_axis(dAxis(0,100,-4,4)) >>> plot.show().
After which you should have
To retrieve the plot data, type
xl is the info attribute holding the dependent variable). To see the list of info variables, type
object._info. Following is an example showing the info parameters of the just generated scatter plot.
>>> plot._info ['axis', 'legend', 'title', 'xl', 'yl']
You can create 3D plots with pxDislin as well. The following recreates a previous example. Note that the
d3DSurface object takes a function to be evaluated over a range as the first argument. The second and third arguments specify the start, stop and range of the x and y variables respectively.
>>> def f(x,y): ... dtr = 3.1415 / 180.0 ... return(sin(x*3*dtr)*sin(y*2*dtr)) ... >>> plot = d3DSurface(f,(0,180.0,1),(0,180.0,1)) >>> plot.surface(clr_top=20) >>> plot.surface(clr_bottom=230) >>> plot.show()
With only a brief introduction to the DISLIN package, it is hard to see its full potential. In the coming articles there will more examples of its use and capabilities. I encourage you to read up on both DISLIN and pxDislin to discover for yourself the additional capabilities. Besides, who can resist making 3D color plots of interesting functions? A catalog of some basic plots and associated functions can be found here. Have fun!
With the introductions behind us, next month we will take a graphical look into the world of linear algebra. By using the tools of geometry we can gain some insight into the meaning of vectors and matrices.
Eric Hagemann specializes in fast algorithms for crunching numbers on all varieties of computers from embedded to mainframe.
Read more Numerically Python columns.
Discuss this article in the O'Reilly Network Python Forum.
Return to the Python DevCenter.