Python DevCenter
oreilly.comSafari Books Online.Conferences.


Adding Data Visualization to Python for Producing Graphs
Pages: 1, 2, 3, 4

Going Beyond the Basics

Creating custom plots or significantly modifying some of the previous examples will force you to engross yourself in the DISLIN function set. If this is your desire, you need to check out the pxDislin module written by Paul Magwene available here. PxDislin is an Object-Oriented wrapper for DISLIN that provides a straightforward and simple programming model.


To get started with pxDislin, start a new console session and import the library.

>>> from pxdislin import *

This takes care of importing the DISLIN library itself. Of course if you want NumPy (don't we all?), remember to import it as well.

PxDislin has a class hierarchy that builds on the basic dPlot object. The most basic graphic consists of a dPlot object incorporating a dAxis object. The dPlot object can be thought as the canvas on which the drawing is made. The dAxis object helps to define the size. Let's try an example

>>> plot = dPlot()
>>> axis = dAxis(-10,10,-10,10)
>>> plot.add_axis(axis)

The first line creates the basic plot object. The second line created an axis object. The third associated the two and the fourth caused the plot to be drawn. If you are following along, you should have a rectangular window on your screen with an empty axis.

PxDislin objects support many options via attributes. The attributes are broken up into 'options' and 'info' types. Options refer to features of a plot that you might want to change after the object is created, perhaps to alter its appearance. Options are set by calling the objects config(). In pxDislin, calling object.config() is equivalent to calling object(). In the above example click the right mouse button to clear the plot and type


A new plot window should appear looking as before but with a title string. To see a list of options for a particular object, simply type the object name followed by an empty set of parenthesis.

>>> plot()


app_look = console color = fore continue_key = Return display_type = screen external_ID = None external_type = window filename = dis.out font = default font_size = 36 height = 500 origin = (25, 25) page_height = 3000 page_width = 3000 ps_origin = (25, 25) pscript = None pscript = None psfont = courier psfont = courier scale = 1.0 screen_mode = normal size = None suppress_disout = 1 tsize = 64 ttext = test width = 500 *END OBJECT: dPlot

Notice the nice additional feature of the command telling you what the current setting is for each option.

The info attributes directly affect the generation of the object (typically they contain the data to be plotted) and are set by using the . (dot) notation. The info attributes are typically passed into the object at creation time as parameters to the function.

Pages: 1, 2, 3, 4

Next Pagearrow

Sponsored by: