def plot2(w): # Set up the viewport and window using w.plenv. The range in X # is -2.0 to 10.0, and the range in Y is -0.4 to 2.0. The axes # are scaled separately (just = 0), and we draw a box with # axes (axis = 1). w.plcol0(1) w.plenv(-2.0, 10.0, -0.4, 1.2, 0, 1) w.plcol0(2) w.pllab("(x)", "sin(x)/x", "#frPLplot Example 1 - Sinc Function") # Fill up the arrays x = (arange(100) - 19) / 6.0 if 0.0 in x: #replace 0.0 by small value that gives the same sinc(x) result. x[list(x).index(0.0)] = 1.e-30 y = sin(x) / x # Draw the line w.plcol0(3) w.plline(x, y) w.plflush()
def plot1(w, xscale, yscale, xoff, yoff): x = xoff + (xscale / 60.) * (1 + arange(60)) y = yoff + yscale * pow(x, 2.) xmin = x[0] xmax = x[59] ymin = y[0] ymax = y[59] xs = x[3::10] ys = y[3::10] # Set up the viewport and window using w.plenv. The range in X # is 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes # are scaled separately (just = 0), and we just draw a # labelled box (axis = 0). w.plcol0(1) w.plenv(xmin, xmax, ymin, ymax, 0, 0) w.plcol0(6) w.pllab("(x)", "(y)", "#frPLplot Example 1 - y=x#u2") # Plot the data points w.plcol0(9) w.plpoin(xs, ys, 9) # Draw the line through the data w.plcol0(4) w.plline(x, y) w.plflush()
def plot4(w): dtr = pi / 180.0 x0 = cos(dtr * arange(361)) y0 = sin(dtr * arange(361)) # Set up viewport and window, but do not draw box w.plenv(-1.3, 1.3, -1.3, 1.3, 1, -2) i = 0.1 * arange(1, 11) #outerproduct(i,x0) and outerproduct(i,y0) is what we are #mocking up here since old Numeric version does not have outerproduct. i.shape = (-1, 1) x = i * x0 y = i * y0 # Draw circles for polar grid for i in range(10): w.plline(x[i], y[i]) w.plcol0(2) for i in range(12): theta = 30.0 * i dx = cos(dtr * theta) dy = sin(dtr * theta) # Draw radial spokes for polar grid w.pljoin(0.0, 0.0, dx, dy) # Write labels for angle text = ` int(theta) ` #Slightly off zero to avoid floating point logic flips at 90 and 270 deg. if dx >= -0.00001: w.plptex(dx, dy, dx, dy, -0.15, text) else: w.plptex(dx, dy, -dx, -dy, 1.15, text) # Draw the graph r = sin((dtr * 5.) * arange(361)) x = x0 * r y = y0 * r w.plcol0(3) w.plline(x, y) w.plcol0(4) w.plmtex("t", 2.0, 0.5, 0.5, "#frPLplot Example 3 - r(#gh)=sin 5#gh") w.plflush()
def plot5(w): mark = 1500 space = 1500 clevel = -1. + 0.2 * arange(11) xx = (arange(XPTS) - XPTS / 2) / float((XPTS / 2)) yy = (arange(YPTS) - YPTS / 2) / float((YPTS / 2)) - 1. xx.shape = (-1, 1) z = (xx * xx) - (yy * yy) # 2.*outerproduct(xx,yy) for new versions of Numeric which have outerproduct. w_array = 2. * xx * yy w.plenv(-1.0, 1.0, -1.0, 1.0, 0, 0) w.plcol0(2) w.plcont(z, clevel, mypltr, tr) w.plstyl([mark], [space]) w.plcol0(3) w.plcont(w_array, clevel, mypltr, tr) w.plstyl([], []) w.plcol0(1) w.pllab("X Coordinate", "Y Coordinate", "Streamlines of flow") w.plflush()
Example of plotting lines with pyvisi This is the original code used to develop the plplot renderer module """ # set up some data to plot from Numeric import * x = arange(10, typecode=Float) y = x**2 import plplot plplot.plsdev("xwin") plplot.plinit() plplot.plenv(min(x), max(x), min(y), max(y), 0, 1) plplot.pllab("x", "x**2", "Example 2D plot") plplot.plline(x, y) plplot.plend() # to save as well, have to set everything up again, and replot # save as png plplot.plsdev("png") plplot.plsfnam("simplePlotExample.png") plplot.plinit() plplot.plenv(min(x), max(x), min(y), max(y), 0, 1) plplot.pllab("x", "x**2", "Example 2D plot") plplot.plline(x, y) plplot.plend() # save as postscript
#!/usr/bin/env python # Append to effective python path so that can find plplot modules. from plplot_python_start import * import sys import plplot as w from numpy import * # Parse and process command line arguments w.plparseopts(sys.argv, w.PL_PARSE_FULL) # Initialize plplot w.plinit() w.plssym(0., 10.) w.plenv(0, 1, 0, 1, 0, 0) w.plpoin([1.0], [0.5], 0) w.plend()
def plenv(x1, x2, y1, y2, just, axis): if PLPLOT: plg.plenv(x1,x2,y1,y2,just,axis) else: plg.pgenv(x1,x2,y1,y2,just,axis)
# sides of box in normalised coordinates # (these are values recommended by plplot in an example) basex = 2.0 basey = 4.0 height = 3.0 # angle to view box alt = 45.0 az = 30.0 side = 1 opt = 3 # plots a net of lines plplot.plsdev("xwin") plplot.plinit() plplot.plenv(xMin2D, xMax2D, yMin2D, yMax2D, 0, -2) plplot.plw3d(basex, basey, height, xMin, xMax, yMin, yMax, zMin, zMax, alt, az) plplot.plmtex("t", 1.0, 0.5, 0.5, "Example surface plot") plplot.plbox3("bnstu", "x axis", 0.0, 0, "bnstu", "y axis", 0.0, 0, "bcdmnstuv", "z axis", 0.0, 0) plplot.plsurf3d(x, y, z, 0, ()) plplot.plend() # to save as well, have to set everything up again, and replot # save as png plplot.plsdev("png") plplot.plsfnam("surfacePlot.png") plplot.plinit()
for i in range(len(x)): for j in range(len(y)): z[i,j] = x[i]*exp(-x[i]*x[i] - y[j]*y[j]) import plplot # determine the min and max of x xMin = min(x) xMax = max(x) yMin = min(y) yMax = max(y) plplot.plsdev("xwin") plplot.plinit() plplot.plenv(xMin, xMax, yMin, yMax, 0, 1) plplot.pllab("x", "y", "Example shaded contour plot") plshades(zz, shedge, fill_width, 1, pltr1, xg1, yg1) zmin = min(zz.flat) zmax = max(zz.flat) clevel = zmin + (zmax - zmin) * (arrayrange(NS)+0.5)/NS shedge = zmin + (zmax - zmin) * (arrayrange(NS+1))/NS plplot.plend() # to save as well, have to set everything up again, and replot # save as png plplot.plsdev("png") plplot.plsfnam("contourPlot.png")