def plfbox(x0, y0): x = numpy.array([x0, x0, x0 + 1.0, x0 + 1.0]) y = numpy.array([0.0, y0, y0, 0.0]) plplot.plfill(x, y) plplot.plcol0(1) plplot.pllsty(1) plplot.plline(x, y)
def mouseMoveEvent(self, qmev): print "MOVE IN PYTHON" if (hasattr(plplot, "semaphore")): if (plplot.owner is not self): plplot.semaphore.acquire() plplot.owner = self self.set_stream() if (qmev.state() == 1): x = qmev.x() y = qmev.y() (xa, ya) = plplot.plPixel2U(self.xstart, self.ystart) (xb, yb) = plplot.plPixel2U(x, y) plplot.plmoveimage(xb - xa, yb - ya) plplot.plNoBufferNoPixmap() plplot.plRestoreWrite2BufferPixmap() else: plplot.plNoBufferNoPixmap() (xu, yu) = plplot.plPixel2U(qmev.x(), qmev.y()) (xmin, xmax, ymin, ymax) = plplot.plPgvpw() plplot.plline([xmin, xmax], [yu, yu]) plplot.plline([xu, xu], [ymin, ymax]) plplot.plRestoreWrite2BufferPixmap() if (hasattr(plplot, "semaphore")): plplot.semaphore.release()
def plot3(w): # For the final graph we wish to override the default tick # intervals, so do not use w.plenv w.pladv(0) # Use standard viewport, and define X range from 0 to 360 # degrees, Y range from -1.2 to 1.2. w.plvsta() w.plwind(0.0, 360.0, -1.2, 1.2) # Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y. w.plcol0(1) w.plbox("bcnst", 60.0, 2, "bcnstv", 0.2, 2) # Superimpose a dashed line grid, with 1.5 mm marks and spaces. w.plstyl([1500], [1500]) w.plcol0(2) w.plbox("g", 30.0, 0, "g", 0.2, 0) w.plstyl([], []) w.plcol0(3) w.pllab("Angle (degrees)", "sine", "#frPLplot Example 1 - Sine function") x = 3.6 * arange(101) y = sin((pi / 180.) * x) w.plcol0(4) w.plline(x, y) w.plflush()
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 mouseMoveEvent (self, qmev ) : print "MOVE IN PYTHON" if(hasattr(plplot,"semaphore")): if(plplot.owner is not self): plplot.semaphore.acquire() plplot.owner=self self.set_stream() if(qmev.state()==1): x=qmev.x() y=qmev.y() (xa,ya)=plplot.plPixel2U(self.xstart,self.ystart ) (xb,yb)=plplot.plPixel2U(x, y) plplot.plmoveimage(xb-xa,yb-ya) plplot.plNoBufferNoPixmap() plplot.plRestoreWrite2BufferPixmap() else: plplot.plNoBufferNoPixmap() (xu,yu)=plplot.plPixel2U(qmev.x(), qmev.y()) (xmin,xmax,ymin,ymax)=plplot.plPgvpw() plplot.plline( [xmin,xmax],[yu,yu]) plplot.plline( [xu,xu],[ymin, ymax]) plplot.plRestoreWrite2BufferPixmap() if(hasattr(plplot,"semaphore")): plplot.semaphore.release()
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 plotCurves(self): self.plot.clearWidget() # 1st plot indexes = numpy.arange(0, 360.1, 1.0) sine = numpy.sin(indexes * 3.14159 / 180.0) cosine = numpy.cos(indexes * 3.14159 / 180.0) plplot.pladv(0) plplot.plvpor(0.05, 0.95, 0.05, 0.45) plplot.plwind(0.0, 360.0, -1.2, 1.2) plplot.plcol0(2) plplot.plbox("bcnst", 0., 0, "bcnst", 0., 0) plplot.plcol0(1) plplot.plwidth(2) plplot.plline(indexes, sine) plplot.plcol0(3) plplot.plwidth(1) plplot.pllsty(2) plplot.plline(indexes, cosine) plplot.pllsty(1) plplot.plcol0(2) plplot.plmtex("t", 1., 0.5, 0.5, "Sines") # 2nd plot indexes = numpy.arange(-1.0, 1.0, 0.01) square = indexes * indexes cubic = square * indexes plplot.plvpor(0.05, 0.95, 0.55, 0.95) plplot.plwind(-1., 1., -1., 1.) plplot.plcol0(2) plplot.plbox("bcnst", 0., 0, "bcnst", 0., 0) plplot.plcol0(1) plplot.plwidth(2) plplot.plline(indexes, square) plplot.plcol0(3) plplot.plwidth(1) plplot.pllsty(2) plplot.plline(indexes, cubic) plplot.pllsty(1) plplot.plcol0(2) plplot.plmtex("t", 1., 0.5, 0.5, "Square & Cubic") self.update()
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 plplot.plsdev("psc") plplot.plsfnam("simplePlotExample.ps")
# 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() # Like yellow lines better. w.plcol0(2) w.pladv(0) w.plvpor(0.1, 0.9, 0.1, 0.9) w.plwind(0., 1., 0., 1.) x=0.*arange(2) y=1.*arange(2) w.plline(x,y) x=0.1*arange(2) y=0.5+0.*arange(2) w.plline(x,y) w.plschr(0., 4.) #w.plmtex("l", 0., 0.5, 0.5, "#[0x00d7]#[0x00d7]#[0x00d7]#[0x00d7]#[0x00d7]#[0x00d7]#[0x00d7]") w.plmtex("l", 0., 0.5, 0.5, "HHHHHHH") # Terminate plplot w.plend()
def plline(x,y): if PLPLOT: plg.plline(x,y) else: plg.pgline(x,y)
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") plplot.plinit() plplot.plenv(xMin, xMax, yMin, yMax, 0, 1) plplot.pllab("x", "y", "Example shaded contour plot") plplot.plline(x, y1) plplot.plend() # vim: expandtab shiftwidth=4:
# determine the min and max of x xMin = min(x) xMax = max(x) # determine the global min and max of all the y's yAll = concatenate( [y1, y2, y3] ) yMin = min(yAll) yMax = max(yAll) plplot.plsdev("xwin") plplot.plinit() plplot.plenv(xMin, xMax, yMin, yMax, 0, 1) plplot.pllab("x", "y", "Example 2D plot") plplot.plline(x, y1) plplot.plline(x, y2) plplot.plline(x, y3) plplot.plend() # to save as well, have to set everything up again, and replot # save as png plplot.plsdev("png") plplot.plsfnam("multiCurveLinePlot.png") plplot.plinit() plplot.plenv(xMin, xMax, yMin, yMax, 0, 1) plplot.pllab("x", "y", "Example 2D plot") plplot.plline(x, y1) plplot.plline(x, y2) plplot.plline(x, y3) plplot.plend()