Example #1
0
    def __init__(self):
        QtGui.QMainWindow.__init__(self, None)

        # UI setup
        self.curvesAct = QtGui.QAction("Curves", self)
        self.histogramAct = QtGui.QAction("Histogram", self)
        self.interactiveAct = QtGui.QAction("Interactive Selection", self)
        self.plotMenu = self.menuBar().addMenu("Plot")
        self.plotMenu.addAction(self.curvesAct)
        self.plotMenu.addAction(self.histogramAct)
        self.plotMenu.addAction(self.interactiveAct)
        self.connect(self.curvesAct, QtCore.SIGNAL("triggered()"),
                     self.plotCurves)
        self.connect(self.histogramAct, QtCore.SIGNAL("triggered()"),
                     self.plotHistogram)
        self.connect(self.interactiveAct, QtCore.SIGNAL("triggered()"),
                     self.interactive)

        # PLplot setup
        self.plot = plplot_pyqt4.QtExtWidget(842, 595, self)
        self.setCentralWidget(self.plot)
        plplot_pyqt4.plsetqtdev(self.plot)
        plplot.plsdev("extqt")
        plplot.plinit()

        self.resize(600, 600)
        plplot.pladv(0)
Example #2
0
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()
Example #3
0
    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()
def main(w):
    w.pladv(0)
    w.plcol0(2)
    w.plvpor(0.02, 0.98, 0.02, 0.90)
    w.plwind(0.0, 1.0, 0.0, 1.0)
    w.plsfci(0)
    w.plschr(0., 2.5)
    # The text is Genesis, Chapter 1 verse 3 in Hebrew.
    w.plptex(0.5, 0.5, 1., 0., 0.5,
             "וַיֹּאמֶר אֱלֹהִים יְהִי אוֹר וַיְהִי אוֹר וַיַּרְא")
    w.plschr(0., 1.0)
    # Restore defaults
    w.plcol0(1)
Example #5
0
def main(w):

    FCI_COMBINATIONS = 30
    w.plsfont(0, 0, 0)
    for index_fci in range(0, FCI_COMBINATIONS):
        family_index = index_fci % 5
        style_index = (index_fci / 5) % 3
        weight_index = ((index_fci / 5) / 3) % 2
        title = "Type 1 glyphs for family = " + family[
            family_index] + ", style = " + style[
                style_index] + ", weight = " + weight[weight_index]
        w.pladv(0)

        # Set up viewport and window

        w.plcol0(2)
        w.plvpor(0.1, 1.0, 0.1, 0.9)
        w.plwind(0.0, 1.0, 0.0, 1.0)

        # Draw the grid using w.plbox

        w.plbox("bcg", 1. / 16., 0, "bcg", 1. / 16., 0)

        # Write the digits below the frame

        w.plcol0(15)
        for i in range(16):
            w.plmtex("b", 1.5, ((i + 0.5) / 16.), 0.5, str(i))

        k = 0
        w.plmtex("t", 1.5, 0.5, 0.5, title)
        for i in range(16):

            # Write the digits to the left of the frame

            w.plmtex("lv", 1.0, (1.0 - (i + 0.5) / 16.), 1.0, str(16 * i))

            w.plsfont(family_index, style_index, weight_index)
            for j in range(16):
                x = (j + 0.5) / 16.
                y = 1. - (i + 0.5) / 16

                # Display the Type 1 glyph corresponding to k
                glyph_string = unichr(k).encode('utf-8')
                # Escape the escape.
                if glyph_string == "#":
                    glyph_string = "##"
                w.plptex(x, y, 1., 0., 0.5, glyph_string)
                k = k + 1
            w.plsfont(0, 0, 0)
Example #6
0
    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()
Example #7
0
    def __init__(self):
        QtGui.QMainWindow.__init__(self, None)

        # UI setup
        self.curvesAct = QtGui.QAction("Curves", self)
        self.histogramAct = QtGui.QAction("Histogram", self)
        self.interactiveAct = QtGui.QAction("Interactive Selection", self)
        self.plotMenu = self.menuBar().addMenu("Plot")
        self.plotMenu.addAction(self.curvesAct)
        self.plotMenu.addAction(self.histogramAct)
        self.plotMenu.addAction(self.interactiveAct)
        self.connect(self.curvesAct, QtCore.SIGNAL("triggered()"), self.plotCurves)
        self.connect(self.histogramAct, QtCore.SIGNAL("triggered()"), self.plotHistogram)
        self.connect(self.interactiveAct, QtCore.SIGNAL("triggered()"), self.interactive)

        # PLplot setup
        self.plot = plplot_pyqt4.QtExtWidget(842, 595, self)
        self.setCentralWidget(self.plot)
        plplot_pyqt4.plsetqtdev(self.plot)
        plplot.plsdev("extqt")
        plplot.plinit()

        self.resize(600,600)
        plplot.pladv(0)
Example #8
0
def main(w):

    x = (arange(XPTS) - (XPTS / 2)) / float(XPTS / 2)
    y = (arange(YPTS) - (YPTS / 2)) / float(YPTS / 2)
    x = 1.5*x
    y = 0.5 + y
    x.shape = (-1,1)
    r2 = (x*x) + (y*y)
    z = (1. - x)*(1. - x) + 100 * (x*x - y)*(x*x - y)
    # The log argument may be zero for just the right grid.  */
    z = log(choose(greater(z,0.), (exp(-5.), z)))

    x.shape = (-1,)
    zmin = min(z.flat)
    zmax = max(z.flat)
    nlevel = 10
    step = (zmax-zmin)/(nlevel+1)
    clevel = zmin + step + arange(nlevel)*step
    w.plschr(0., 1.8)
    w.plwidth(1)
    w.pladv(0)
    w.plvpor(0.0, 1.0, 0.0, 1.0)
    w.plwind(-0.43, 0.840, 0.05, 0.48)
    w.plcol0(1)
    w.plw3d(1.0, 1.0, 1.0, -1.5, 1.5, -0.5, 1.5, zmin, zmax,
          alt, az)
    w.plbox3("bnstu", "", 0.0, 0,
           "bnstu", "", 0.0, 0,
           "bcdmnstuv", "", 0.0, 0)
    # If converting the -dev svg result later with the ImageMagick
    # "convert" application or viewing the svg result with the ImageMagick
    # "display" application must compensate for the librsvg-2.22
    # positioning bug since librsvg is what ImageMagick uses
    # to interpret SVG results.
    if_rsvg_bug = True
    if if_rsvg_bug:
        shift = 1.00
    else:
        shift = 1.07
    w.plmtex3("zs", 5.0, shift, 1.0, "z axis")

    w.plcol0(2)
    # magnitude colored plot with faceted squares
    cmap1_init(w, 0)
    w.plsurf3d(x, y, z, w.MAG_COLOR | w.FACETED, ())

    # Shading to provide a good background for legend.
    x1 = 0.10
    x2 = 0.8
    w.plvpor(0.0, 1.0, 0.0, 1.0)
    w.plwind(0.0, 1.0, 0.0, 1.0)
    # Completely opaque from 0. to x1
    w.plscol0a(15, 0, 0, 0, 1.0)
    w.plcol0(15)
    x=array([0., 0., x1, x1])
    y=array([0., 1., 1., 0.])
    w.plfill(x,y)
    # Black transparent gradient.
    pos = array([0.0, 1.0])
    rcoord = array([0.0, 0.0])
    gcoord = array([0.0, 0.0])
    bcoord = array([0.0, 0.0])
    acoord = array([1.0, 0.0])
    rev = array([0, 0])
    w.plscmap1n(2)
    w.plscmap1la(1, pos, rcoord, gcoord, bcoord, acoord, rev)
    x=array([x1, x1, x2, x2])
    w.plgradient(x,y,0.)
    # Logo Legend
    w.plscol0a(15, 255, 255, 255, 1.0)
    w.plcol0(15)
    x1 = 0.03
    w.plschr(0., 2.9)
    w.plsfont(w.PL_FCI_SANS, w.PL_FCI_UPRIGHT, w.PL_FCI_BOLD)
    w.plptex(x1, 0.57, 1.0, 0.0, 0.0, "PLplot")
    w.plschr(0., 1.5)
    w.plptex(x1, 0.30, 1.0, 0.0, 0.0,
           "The ultimate in cross-platform plotting")
Example #9
0
# 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()
Example #10
0
def main(w):

    status = 0

    # Test if device initialization screwed around with the preset
    # compression parameter.
    compression2 = w.plgcompression()
    sys.stdout.write("Output various PLplot parameters\n")
    sys.stdout.write("compression parameter = %d\n" % compression2)
    if compression2 != compression1:
        sys.stderr.write("plgcompression test failed\n")
        status = 1

    # Exercise w.plscolor, w.plscol0, w.plscmap1, and w.plscmap1a to make sure
    # they work without any obvious error messages.
    w.plscolor(1)
    w.plscol0(1, 255, 0, 0)
    r1 = [0, 255]
    g1 = [255, 0]
    b1 = [0, 0]
    a1 = [1.0, 1.0]
    w.plscmap1(r1, g1, b1)
    w.plscmap1a(r1, g1, b1, a1)

    level2 = w.plglevel()
    sys.stdout.write("level parameter = %d\n" % level2)
    if level2 != 1:
        sys.stderr.write("plglevel test failed.\n")
        status = 1

    w.pladv(0)
    xmin0, xmax0, ymin0, ymax0 = (0.01, 0.99, 0.02, 0.49)
    w.plvpor(xmin0, xmax0, ymin0, ymax0)
    (xmin, xmax, ymin, ymax) = w.plgvpd()
    sys.stdout.write("plvpor: xmin, xmax, ymin, ymax = %f %f %f %f\n" %
                     (xmin, xmax, ymin, ymax))
    if xmin != xmin0 or xmax != xmax0 or ymin != ymin0 or ymax != ymax0:
        sys.stderr.write("plgvpd test failed\n")
        status = 1
    xmid = 0.5 * (xmin + xmax)
    ymid = 0.5 * (ymin + ymax)

    xmin0, xmax0, ymin0, ymax0 = (0.2, 0.3, 0.4, 0.5)
    w.plwind(xmin0, xmax0, ymin0, ymax0)
    (xmin, xmax, ymin, ymax) = w.plgvpw()
    sys.stdout.write("plwind: xmin, xmax, ymin, ymax = %f %f %f %f\n" %
                     (xmin, xmax, ymin, ymax))
    if xmin != xmin0 or xmax != xmax0 or ymin != ymin0 or ymax != ymax0:
        sys.stderr.write("plgvpw test failed\n")
        status = 1

    # Get world coordinates for middle of viewport
    (wx, wy, win) = w.plcalc_world(xmid, ymid)
    sys.stdout.write("world parameters: wx, wy, win = %f %f %d\n" %
                     (wx, wy, win))
    if abs(wx - 0.5 * (xmin + xmax)) > 1.0E-5 or abs(wy - 0.5 *
                                                     (ymin + ymax)) > 1.0E-5:
        sys.stderr.write("plcalc_world test failed\n")
        status = 1

    # Retrieve and print the name of the output file (if any)
    fnam = w.plgfnam()
    if fnam == '':
        sys.stdout.write("No output file name is set\n")
    else:
        sys.stdout.write("Output file name read\n")
    sys.stderr.write("Output file name is %s\n" % fnam)

    # Set and get the number of digits used to display axis labels
    # Note digits is currently ignored in w.pls[xyz]ax and
    # therefore it does not make sense to test the returned value.
    w.plsxax(3, 0)
    (digmax, digits) = w.plgxax()
    sys.stdout.write("x axis parameters: digmax, digits = %d %d\n" %
                     (digmax, digits))
    if digmax != 3:
        sys.stderr.write("plgxax test failed\n")
        status = 1

    w.plsyax(4, 0)
    (digmax, digits) = w.plgyax()
    sys.stdout.write("y axis parameters: digmax, digits = %d %d\n" %
                     (digmax, digits))
    if digmax != 4:
        sys.stderr.write("plgyax test failed\n")
        status = 1

    w.plszax(5, 0)
    (digmax, digits) = w.plgzax()
    sys.stdout.write("z axis parameters: digmax, digits = %d %d\n" %
                     (digmax, digits))
    if digmax != 5:
        sys.stderr.write("plgzax test failed\n")
        status = 1

    (mar0, aspect0, jx0, jy0) = (0.05, w.PL_NOTSET, 0.1, 0.2)
    w.plsdidev(mar0, aspect0, jx0, jy0)
    (mar, aspect, jx, jy) = w.plgdidev()
    sys.stdout.write(
        "device-space window parameters: mar, aspect, jx, jy = %f %f %f %f\n" %
        (mar, aspect, jx, jy))
    if mar != mar0 or jx != jx0 or jy != jy0:
        sys.stderr.write("plgdidev test failed\n")
        status = 1

    ori0 = 1.0
    w.plsdiori(ori0)
    ori = w.plgdiori()
    sys.stdout.write("ori parameter = %f\n" % ori)
    if ori != ori0:
        sys.stderr.write("plgdiori test failed\n")
        status = 1

    (xmin0, ymin0, xmax0, ymax0) = (0.1, 0.2, 0.9, 0.8)
    w.plsdiplt(xmin0, ymin0, xmax0, ymax0)
    (xmin, ymin, xmax, ymax) = w.plgdiplt()
    sys.stdout.write(
        "plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f\n"
        % (xmin, ymin, xmax, ymax))
    if xmin != xmin0 or ymin != ymin0 or xmax != xmax0 or ymax != ymax0:
        sys.stderr.write("plgdiplt test failed\n")
        status = 1

    (zxmin0, zymin0, zxmax0, zymax0) = (0.1, 0.1, 0.9, 0.9)
    w.plsdiplz(zxmin0, zymin0, zxmax0, zymax0)
    (zxmin, zymin, zxmax, zymax) = w.plgdiplt()
    sys.stdout.write(
        "zoomed plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f\n"
        % (zxmin, zymin, zxmax, zymax))
    if abs(zxmin - (xmin + (xmax - xmin) * zxmin0)) > 1.0E-5 or abs(
            zymin - (ymin + (ymax - ymin) * zymin0)) > 1.0E-5 or abs(
                zxmax - (xmin + (xmax - xmin) * zxmax0)) > 1.0E-5 or abs(
                    zymax - (ymin + (ymax - ymin) * zymax0)) > 1.0E-5:
        sys.stderr.write("plsdiplz test failed\n")
        status = 1

    (r0, g0, b0) = (10, 20, 30)
    w.plscolbg(r0, g0, b0)
    (r, g, b) = w.plgcolbg()
    sys.stdout.write("background colour parameters: r, g, b = %d %d %d\n" %
                     (r, g, b))
    if r != r0 or g != g0 or b != b0:
        sys.stderr.write("plgcolbg test failed\n")
        status = 1

    (r0, g0, b0, a0) = (20, 30, 40, 0.5)
    w.plscolbga(r0, g0, b0, a0)
    (r, g, b, a) = w.plgcolbga()
    sys.stdout.write(
        "background/transparency colour parameters: r, g, b, a = %d %d %d %f\n"
        % (r, g, b, a))
    if r != r0 or g != g0 or b != b0 or a != a0:
        sys.stderr.write("plgcolbga test failed\n")
        status = 1

    # Restore defaults
    # cmap0 default color palette.
    w.plspal0("cmap0_default.pal")
    # cmap1 default color palette.
    w.plspal1("cmap1_default.pal", 1)
Example #11
0
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)