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 plotHistogram(self): 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) self.plot.clearWidget(); y0 = numpy.array([5, 15, 12, 24, 28, 30, 20, 8, 12, 3]) pos = numpy.array([0.0, 0.25, 0.5, 0.75, 1.0]) red = numpy.array([0.0, 0.25, 0.5, 1.0, 1.0]) green = numpy.array([1.0, 0.5, 0.5, 0.5, 1.0]) blue = numpy.array([1.0, 1.0, 0.5, 0.25, 0.0]) plplot.pladv(0) plplot.plvsta() plplot.plcol0(2) plplot.plwind(1980.0, 1990.0, 0.0, 35.0) plplot.plbox("bc", 1.0, 0, "bcnv", 10.0, 0) plplot.plcol0(2) plplot.pllab("Year", "Widget Sales (millions)", "#frPLplot Example 12") plplot.plscmap1l(1,pos,red,green,blue) for i in range(10): plplot.plcol1(i/9.0) plplot.plpsty(0) plfbox((1980. + i), y0[i]) string = "%.0f" % (y0[i]) plplot.plptex((1980. + i + .5), (y0[i] + 1.), 1.0, 0.0, .5, string) string = "%d" % (1980 + i) plplot.plmtex("b", 1.0, ((i + 1) * .1 - .05), 0.5, string) self.update()
def main(w): nsteps = 1000 # If db is used the plot is much more smooth. However, because of the # async X behaviour, one does not have a real-time scripcharter. # w.plsetopt("db", "") # w.plsetopt("np", "") # User sets up plot completely except for window and data # Eventually settings in place when strip chart is created will be # remembered so that multiple strip charts can be used simultaneously. # # Specify some reasonable defaults for ymin and ymax # The plot will grow automatically if needed (but not shrink) ymin = -0.1 ymax = 0.1 # Specify initial tmin and tmax -- this determines length of window. # Also specify maximum jump in t # This can accomodate adaptive timesteps tmin = 0. tmax = 10. tjump = 0.3 # percentage of plot to jump # Axes options same as w.plbox. # Only automatic tick generation and label placement allowed # Eventually I ll make this fancier colbox = 1 collab = 3 styline = [2, 3, 4, 5] colline = [2, 3, 4, 5] legline = ["sum", "sin", "sin*noi", "sin+noi"] xlab = 0. ylab = 0.25 # legend position autoy = 1 # autoscale y acc = 1 # don t scrip, accumulate w.pladv(0) w.plvsta() # Register our error variables with PLplot # From here on, we're handling all errors here #w.plsError(&pl_errcode, errmsg) id1 = w.plstripc("bcnst", "bcnstv", tmin, tmax, tjump, ymin, ymax, xlab, ylab, autoy, acc, colbox, collab, colline, styline, legline, "t", "", "Strip chart demo") # Let plplot handle errors from here on #w.plsError(NULL, NULL) autoy = 0 # autoscale y acc = 1 # accumulate # This is to represent a loop over time # Let's try a random walk process y1 = y2 = y3 = y4 = 0.0 dt = 0.1 for n in range(nsteps): sleep(0.01) t = n * dt noise = w.plrandd() - 0.5 y1 = y1 + noise y2 = sin(t * pi / 18.) y3 = y2 * noise y4 = y2 + noise / 3. # There is no need for all pens to have the same number of # points or beeing equally time spaced. if n % 2: w.plstripa(id1, 0, t, y1) if n % 3: w.plstripa(id1, 1, t, y2) if n % 4: w.plstripa(id1, 2, t, y3) if n % 5: w.plstripa(id1, 3, t, y4) # Destroy strip chart and it's memory w.plstripd(id1)