Example #1
0
def main():

	# Parse and process command line arguments

	# pl.ParseOpts(sys.argv, pl.PARSE_FULL)

	# Initialize plplot

	pl.init()

	for k in range(4):
		test_poly(k)

	x = []
	y = []
	z = []

	# From the mind of a sick and twisted physicist...

	for i in range(NPTS):
		z.append(-1. + 2. * i / NPTS)

		# Pick one ...

##		r = 1. - ( (float) i / (float) NPTS )
		r = z[i]

		x.append(r * math.cos( 2. * math.pi * 6. * i / NPTS ))
		y.append(r * math.sin( 2. * math.pi * 6. * i / NPTS ))

	for k in range(4):
		pl.adv(0)
		pl.vpor(0.0, 1.0, 0.0, 0.9)
		pl.wind(-1.0, 1.0, -0.9, 1.1)
		pl.col(1)
		pl.w3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0,
		       alt[k], az[k])
		pl.box3("bnstu", "x axis", 0.0, 0,
			"bnstu", "y axis", 0.0, 0,
			"bcdmnstuv", "z axis", 0.0, 0)

		pl.col(2)

		if opt[k]:
			pl.line3(x, y, z)
		else:
			pl.poin3(x, y, z, 1)

		pl.col(3)
		title = "#frPLplot Example 18 - Alt=%.0f, Az=%.0f" % (alt[k],
								      az[k])
		pl.mtex("t", 1.0, 0.5, 0.5, title)

	pl.end()
Example #2
0
def main():

    # Parse and process command line arguments

    # pl.ParseOpts(sys.argv, pl.PARSE_FULL)

    # Initialize plplot

    pl.init()

    for k in range(4):
        test_poly(k)

    x = []
    y = []
    z = []

    # From the mind of a sick and twisted physicist...

    for i in range(NPTS):
        z.append(-1. + 2. * i / NPTS)

        # Pick one ...

        ##		r = 1. - ( (float) i / (float) NPTS )
        r = z[i]

        x.append(r * math.cos(2. * math.pi * 6. * i / NPTS))
        y.append(r * math.sin(2. * math.pi * 6. * i / NPTS))

    for k in range(4):
        pl.adv(0)
        pl.vpor(0.0, 1.0, 0.0, 0.9)
        pl.wind(-1.0, 1.0, -0.9, 1.1)
        pl.col(1)
        pl.w3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, alt[k], az[k])
        pl.box3("bnstu", "x axis", 0.0, 0, "bnstu", "y axis", 0.0, 0,
                "bcdmnstuv", "z axis", 0.0, 0)

        pl.col(2)

        if opt[k]:
            pl.line3(x, y, z)
        else:
            pl.poin3(x, y, z, 1)

        pl.col(3)
        title = "#frPLplot Example 18 - Alt=%.0f, Az=%.0f" % (alt[k], az[k])
        pl.mtex("t", 1.0, 0.5, 0.5, title)

    pl.end()
Example #3
0
def test_poly(k):

	draw = [ [ 1, 1, 1, 1 ],
		 [ 1, 0, 1, 0 ],
		 [ 0, 1, 0, 1 ],
		 [ 1, 1, 0, 0 ] ]

	pl.adv(0)
	pl.vpor(0.0, 1.0, 0.0, 0.9)
	pl.wind(-1.0, 1.0, -0.9, 1.1)
	pl.col(1)
	pl.w3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, alt[k], az[k])
	pl.box3("bnstu", "x axis", 0.0, 0,
		"bnstu", "y axis", 0.0, 0,
		"bcdmnstuv", "z axis", 0.0, 0)

	pl.col(2)

	def THETA(a):
		return 2. * math.pi * (a) / 20.
	def PHI(a):
		return math.pi * (a) / 20.1

##      x = r sin(phi) cos(theta)
##      y = r sin(phi) sin(theta)
##      z = r cos(phi)
##      r = 1 :=)

	for i in range(20):
		for j in range(20):
			x = []
			y = []
			z = []

			x.append(math.sin( PHI(j) ) * math.cos( THETA(i) ))
			y.append(math.sin( PHI(j) ) * math.sin( THETA(i) ))
			z.append(math.cos( PHI(j) ))

			x.append(math.sin( PHI(j) ) * math.cos( THETA(i+1) ))
			y.append(math.sin( PHI(j) ) * math.sin( THETA(i+1) ))
			z.append(math.cos( PHI(j) ))

			x.append(math.sin( PHI(j+1) ) * math.cos( THETA(i+1) ))
			y.append(math.sin( PHI(j+1) ) * math.sin( THETA(i+1) ))
			z.append(math.cos( PHI(j+1) ))

			x.append(math.sin( PHI(j+1) ) * math.cos( THETA(i) ))
			y.append(math.sin( PHI(j+1) ) * math.sin( THETA(i) ))
			z.append(math.cos( PHI(j+1) ))

			x.append(math.sin( PHI(j) ) * math.cos( THETA(i) ))
			y.append(math.sin( PHI(j) ) * math.sin( THETA(i) ))
			z.append(math.cos( PHI(j) ))

			# N.B.: The Python poly3 no longer takes a
			# (possibly negative) length argument, so if
			# you want to pass a counterclockwise polygon
			# you now have to reverse the list.  The code
			# above was rearranged to create a clockwise
			# polygon instead of a counterclockwise
			# polygon.

			pl.poly3(x, y, z, draw[k])

	pl.col(3)
	pl.mtex("t", 1.0, 0.5, 0.5, "unit radius sphere" )
Example #4
0
def main():

    # Here are the character strings that appear in the plot legend.

    legend = ["Aardvarks", "Gnus", "Llamas"]

    # ==============  Read in data from input file. =============

    # Parse and process command line arguments

    pl.ParseOpts(sys.argv, pl.PARSE_FULL)

    # First prompt the user for the input data file name

    filename = raw_input("Enter input data file name.\n")

    # and open the file.

    try:
        datafile = open(filename, "r")
    except:
        error("Error opening input file.")

    # Read in all the data.

    try:
        lines = datafile.readlines()
        datafile.close()

        x = []
        data = string.split(lines[0])
        for num in data:
            x.append(string.atof(num))

        y = []
        del lines[0]
        for line in lines:
            yy = []
            data = string.split(line)
            for num in data:
                yy.append(string.atof(num))
            y.append(yy)
    except:
        error("Error while reading data file.")

    # ==============  Graph the data. =============

    # Set graph to portrait orientation. (Default is landscape.)
    # (Portrait is usually desired for inclusion in TeX documents.)

    pl.sori(-1)

    # Initialize plplot

    pl.init()

    # We must call pladv() to advance to the first (and only) subpage.
    # You might want to use plenv() instead of the pladv(), plvpor(),
    # plwind() sequence.

    pl.adv(0)

    # Set up the viewport.  This is the window into which the data is
    # plotted.  The size of the window can be set with a call to
    # plvpor(), which sets the size in terms of normalized subpage
    # coordinates.  I want to plot the lines on the upper half of the
    # page and I want to leave room to the right of the figure for
    # labelling the lines. We must also leave room for the title and
    # labels with plvpor().  Normally a call to plvsta() can be used
    # instead.

    pl.vpor(0.15, 0.70, 0.5, 0.9)

    # We now need to define the size of the window in user coordinates.
    # To do this, we first need to determine the range of the data
    # values.

    xmin, xmax = min(x), max(x)
    ymin = ymax = y[0][0]
    for yy in y:
        yymin, yymax = min(yy), max(yy)
        if yymin < ymin:
            ymin = yymin
        if yymax > ymax:
            ymax = yymax

    # Now set the size of the window. Leave a small border around the
    # data.

    xdiff = (xmax - xmin) / 20.
    ydiff = (ymax - ymin) / 20.
    pl.wind(xmin - xdiff, xmax + xdiff, ymin - ydiff, ymax + ydiff)

    # Call plbox() to draw the axes (see the PLPLOT manual for
    # information about the option strings.)

    pl.box("bcnst", 0.0, 0, "bcnstv", 0.0, 0)

    # Label the axes and title the graph.  The string "#gm" plots the
    # Greek letter mu, all the Greek letters are available, see the
    # PLplot manual.

    pl.lab("Time (weeks)", "Height (#gmparsecs)", "Specimen Growth Rate")

    # Plot the data.  plpoin() draws a symbol at each point.  plline()
    # connects all the points.

    i = 0
    for yy in y:
        pl.poin(x, yy, i + OFFSET)
        pl.line(x, yy)
        i = i + 1

    # Draw legend to the right of the chart.  Things get a little messy
    # here.  You may want to remove this section if you don't want a
    # legend drawn.  First find length of longest string.

    leglen = 0
    for leg in legend:
        j = len(leg)
        if j > leglen:
            leglen = j

    # Now build the string.  The string consists of an element from the
    # legend string array, padded with spaces, followed by one of the
    # symbols used in plpoin above.

    M = len(y)
    i = 0
    for leg in legend:
        if i >= M:
            break

        text = leg
        j = len(text)
        # pad string with spaces
        if j < leglen:
            k = leglen - j
            text = text + ' ' * k

        # pad an extra space

        text = text + ' '

        # insert the ASCII value of the symbol plotted with plpoin()

        text = text + chr(i + OFFSET)

        # plot the string

        pl.mtex("rv", 1., 1. - float(i + 1) / (M + 1), 0., text)
        i = i + 1

    # Don't forget to call PLEND to finish off!

    pl.end()
Example #5
0
def main():

	# Here are the character strings that appear in the plot legend.

	legend = ["Aardvarks", "Gnus", "Llamas"]

	# ==============  Read in data from input file. =============

	# Parse and process command line arguments

	pl.ParseOpts(sys.argv, pl.PARSE_FULL)

	# First prompt the user for the input data file name

	filename = raw_input("Enter input data file name.\n")

	# and open the file.

	try:
		datafile = open(filename, "r")
	except:
		error("Error opening input file.")

	# Read in all the data.

	try:
		lines = datafile.readlines()
		datafile.close()

		x = []
		data = string.split(lines[0])
		for num in data:
			x.append(string.atof(num))

		y = []
		del lines[0]
		for line in lines:
			yy = []
			data = string.split(line)
			for num in data:
				yy.append(string.atof(num))
			y.append(yy)
	except:
		error("Error while reading data file.")

	# ==============  Graph the data. =============

	# Set graph to portrait orientation. (Default is landscape.)
	# (Portrait is usually desired for inclusion in TeX documents.)

	pl.sori(-1)

	# Initialize plplot

	pl.init()

	# We must call pladv() to advance to the first (and only) subpage.
	# You might want to use plenv() instead of the pladv(), plvpor(),
	# plwind() sequence.
	
	pl.adv(0)

	# Set up the viewport.  This is the window into which the data is
	# plotted.  The size of the window can be set with a call to
	# plvpor(), which sets the size in terms of normalized subpage
	# coordinates.  I want to plot the lines on the upper half of the
	# page and I want to leave room to the right of the figure for
	# labelling the lines. We must also leave room for the title and
	# labels with plvpor().  Normally a call to plvsta() can be used
	# instead.

	pl.vpor(0.15, 0.70, 0.5, 0.9)

	# We now need to define the size of the window in user coordinates.
	# To do this, we first need to determine the range of the data
	# values.

	xmin, xmax = min(x), max(x)
	ymin = ymax = y[0][0]
	for yy in y:
		yymin, yymax = min(yy), max(yy)
		if yymin < ymin:
			ymin = yymin
		if yymax > ymax:
			ymax = yymax

	# Now set the size of the window. Leave a small border around the
	# data.

	xdiff = (xmax - xmin) / 20.
	ydiff = (ymax - ymin) / 20.
	pl.wind(xmin - xdiff, xmax + xdiff, ymin - ydiff, ymax + ydiff)

	# Call plbox() to draw the axes (see the PLPLOT manual for
	# information about the option strings.)

	pl.box("bcnst", 0.0, 0, "bcnstv", 0.0, 0)

	# Label the axes and title the graph.  The string "#gm" plots the
	# Greek letter mu, all the Greek letters are available, see the
	# PLplot manual.

	pl.lab("Time (weeks)", "Height (#gmparsecs)", "Specimen Growth Rate")

	# Plot the data.  plpoin() draws a symbol at each point.  plline()
	# connects all the points.

	i = 0
	for yy in y:
		pl.poin(x, yy, i + OFFSET)
		pl.line(x, yy)
		i = i + 1

	# Draw legend to the right of the chart.  Things get a little messy
	# here.  You may want to remove this section if you don't want a
	# legend drawn.  First find length of longest string.

	leglen = 0
	for leg in legend:
		j = len(leg)
		if j > leglen:
			leglen = j

	# Now build the string.  The string consists of an element from the
	# legend string array, padded with spaces, followed by one of the
	# symbols used in plpoin above.

	M = len(y)
	i = 0
	for leg in legend:
		if i >= M:
			break

		text = leg
		j = len(text)
		if j < leglen:		# pad string with spaces
			k = leglen - j
			text = text + ' ' * k

		# pad an extra space

		text = text + ' '

		# insert the ASCII value of the symbol plotted with plpoin()

		text = text + chr(i + OFFSET)

		# plot the string

		pl.mtex("rv", 1., 1. - float(i + 1) / (M + 1), 0., text)
		i = i + 1

	# Don't forget to call PLEND to finish off!

	pl.end()
Example #6
0
def test_poly(k):

    draw = [[1, 1, 1, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 1, 0, 0]]

    pl.adv(0)
    pl.vpor(0.0, 1.0, 0.0, 0.9)
    pl.wind(-1.0, 1.0, -0.9, 1.1)
    pl.col(1)
    pl.w3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, alt[k], az[k])
    pl.box3("bnstu", "x axis", 0.0, 0, "bnstu", "y axis", 0.0, 0, "bcdmnstuv",
            "z axis", 0.0, 0)

    pl.col(2)

    def THETA(a):
        return 2. * math.pi * (a) / 20.

    def PHI(a):
        return math.pi * (a) / 20.1


##      x = r sin(phi) cos(theta)
##      y = r sin(phi) sin(theta)
##      z = r cos(phi)
##      r = 1 :=)

    for i in range(20):
        for j in range(20):
            x = []
            y = []
            z = []

            x.append(math.sin(PHI(j)) * math.cos(THETA(i)))
            y.append(math.sin(PHI(j)) * math.sin(THETA(i)))
            z.append(math.cos(PHI(j)))

            x.append(math.sin(PHI(j)) * math.cos(THETA(i + 1)))
            y.append(math.sin(PHI(j)) * math.sin(THETA(i + 1)))
            z.append(math.cos(PHI(j)))

            x.append(math.sin(PHI(j + 1)) * math.cos(THETA(i + 1)))
            y.append(math.sin(PHI(j + 1)) * math.sin(THETA(i + 1)))
            z.append(math.cos(PHI(j + 1)))

            x.append(math.sin(PHI(j + 1)) * math.cos(THETA(i)))
            y.append(math.sin(PHI(j + 1)) * math.sin(THETA(i)))
            z.append(math.cos(PHI(j + 1)))

            x.append(math.sin(PHI(j)) * math.cos(THETA(i)))
            y.append(math.sin(PHI(j)) * math.sin(THETA(i)))
            z.append(math.cos(PHI(j)))

            # N.B.: The Python poly3 no longer takes a
            # (possibly negative) length argument, so if
            # you want to pass a counterclockwise polygon
            # you now have to reverse the list.  The code
            # above was rearranged to create a clockwise
            # polygon instead of a counterclockwise
            # polygon.

            pl.poly3(x, y, z, draw[k])

    pl.col(3)
    pl.mtex("t", 1.0, 0.5, 0.5, "unit radius sphere")