Print

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

As an example of generating a 3D plot, try the following commands.

``````>>>z_mat = zeros((180,180),Float)
>>>x_ray = arange(180.0)
>>>y_ray = arange(180.0)

>>>dtr = 3.141592654/180.0

>>>for x in x_ray:
for y in y_ray:
z_mat[int(x)][int(y)] = sin(x*3*dtr)*sin(y*2*dtr)
>>>surface(z_mat,x_ray,y_ray)
>>>disfin()``````

The first command creates the result matrix, properly sized beforehand. We use the `zeros()` function to size-up the array and pre-allocate storage space for it. The second argument in `zeros()` declares the zeros in the matrix to be floating point zeros instead of integer ones (which would be created by default). If we left that out, the upcoming calculation would be truncated and stored in the `z_mat` matrix as integer values -- not what we want!

The `surface()` function is the Quickplot routine that generates the following graph.

While this may look exciting, the monochromatic nature is drab. By switching the `surface()` function to the `surshade()` function the following is produced.

Now that's a little better! With color the features of the plot really stand out. As a final example of QuickPlots, switch the `surshade()` function to `surf3()`, which will draw a colored contour plot of the same data. The color bar on the left shows the magnitudes as represented by the colors in the plot.

### Quickplot Modification

You can add custom labels to the axis and change quite a few characteristics of a QuickPlot. This is done by setting variables internal to the plotting package via the `setvar()` routine. Consult the DISLIN Python manual for a complete list of available options. Recreating the first example with the addition of axis labels is shown below.

``````>>> x=arange(100.0)
>>> setvar('X','Independent Variable')
>>> setvar('Y','Dependent Variable')
>>> plot(x,sin(x/3)+cos(x/5))
>>> disfin()``````

 Pages: 1, 2, 3, 4