示例#1
0
import math
from math import *
from pyx import *
from pyx.graph import axis, data

# define some functions for the color values:
def red(x):   return 2*x*(1-x)**5 + 3.5*x**2*(1-x)**3 + 2.1*x*x*(1-x)**2 + 3.0*x**3*(1-x)**2 + x**0.5*(1-(1-x)**2)
def green(x): return 1.5*x**2*(1-x)**3 - 0.8*x**3*(1-x)**2 + 2.0*x**4*(1-x) + x**4
def blue(x):  return 5*x*(1-x)**5 - 0.5*x**2*(1-x)**3 + 0.3*x*x*(1-x)**2 + 5*x**3*(1-x)**2 + 0.5*x**6

# use the implemented converter for the grey value:
def grey(x): return color.rgb(red(x), green(x), blue(x)).grey().color["gray"]

# plot the color values
g = graph.graphxy(width=10, ratio=1)
g.plot(data.function("y(x)=red(x)",   min=0, max=1, context=locals()), [graph.style.line([color.rgb.red])])
g.plot(data.function("y(x)=green(x)", min=0, max=1, context=locals()), [graph.style.line([color.rgb.green])])
g.plot(data.function("y(x)=blue(x)",  min=0, max=1, context=locals()), [graph.style.line([color.rgb.blue])])
g.plot(data.function("y(x)=grey(x)",  min=0, max=1, context=locals()))

# plot the colors
n = 200
x = 0
for i in range(n):
    t = i * 1.0 / (n-1)
    g.fill(path.rect(x, -2, 10.5/(n-1), 1), [color.rgb(red(t), green(t), blue(t))])
    x += 10.0 / n

g.writeEPSfile("palettetest", paperformat=document.paperformat.A4)
g.writePDFfile("palettetest")
示例#2
0
		]) + r'\end{tabular}', 
	   [pyx.text.valign.top,  pyx.trafo.scale(0.7)])

##### 
# 
# New part 12 Apr 2009 - a multitude of lines on the thermodynamics graphs
# 
##### 
if varstring.startswith("n-T"):
    from pyx.style import linestyle, linewidth
    from pyx.color import transparency
    from pyx.graph.style import line
    from pyx.graph import data
    line.defaultlineattrs += [linewidth.thick, transparency(0.5)]
    # Free-fall time < 1.e5 years
    g.plot(data.function("x(y) = 5.31"), [line([linestyle.dashed])])
    # Plot contours of Jeans instability
    for MJeans in (0.0, 1.0): 
	g.plot(data.function("y(x) = 0.491 + 0.6667*MJeans + 0.333*(x-3.0)", 
			     context=locals()), 
	       [line([linestyle.solid, linewidth.Thick])])
    # Plot contours of equilibrium T
    execdir = os.path.dirname(sys.argv[0])
    for Av, D in [
	[0.0, 0.3],
	[2.0, 0.3],
	[10.0, 0.3],
	[0.0, 1.0],
	[2.0, 1.0],
	[10.0, 1.0],
	]:
示例#3
0
    x=axis.linear(
        title="$x$",
        min=-range,
        max=+range,
        painter=p,
        # suppress some ticks by overwriting ...
        manualticks=[tick.tick(0, None, None),
                     tick.tick(range, None, None)]),
    y=axis.linear(
        title=r"$x\sin(x^2)$",
        painter=p,
        manualticks=[tick.tick(0, None, None),
                     tick.tick(3, None, None)]))

g.plot(
    data.function("y(x)=x*sin(x**2)"),
    # Line style is set before symbol style -> symbols will be draw
    # above the line.
    [
        graph.style.line([style.linewidth.Thin, style.linestyle.solid]),
        graph.style.symbol(graph.style.symbol.circle,
                           size=0.1,
                           symbolattrs=[
                               deco.filled([color.rgb.green]),
                               deco.stroked([color.rgb.red])
                           ])
    ])

# manually typeset "0" near the origin
g.dolayout()
x0, y0 = g.pos(0, 0)
示例#4
0
from pyx.deco import barrow, earrow
from pyx.style import linewidth, linestyle
from pyx.graph import graphxy
from pyx.graph.axis import linear
from pyx.graph.axis.painter import regular
from pyx.graph.style import line
from pyx.graph.data import function

mypainter = regular(basepathattrs=[earrow.normal], titlepos=1)
def mycos(x): return -cos(x)+.10*x

g = graphxy(height=5, x2=None, y2=None,
            x=linear(min=-2.5*pi, max=3.3*pi, parter=None,
                      painter=mypainter, title=r"$\delta\phi$"),
            y=linear(min=-2.3, max=2, painter=None))
g.plot(function("y(x)=mycos(x)", context=locals()),
       [line(lineattrs=[linewidth.Thick])])
g.finish()

x1, y1 = g.pos(-pi+.1, mycos(-pi+.1))
x2, y2 = g.pos(-.1, mycos(-.1))
x3, y3 = g.pos(pi+.1, mycos(pi+.1))

g.stroke(path.line(x1-.5, y1, x1+.5, y1), [linestyle.dashed])
g.stroke(path.line(x1-.5, y3, x3+.5, y3), [linestyle.dashed])
g.stroke(path.line(x2-.5, y2, x3+.5, y2), [linestyle.dashed])
g.stroke(path.line(x1, y1, x1, y3), [barrow.normal, earrow.normal])
g.stroke(path.line(x3, y2, x3, y3), [barrow.normal, earrow.normal])
g.text(x1+.2, 0.5*(y1+y3), r"$2\pi\gamma k\Omega$", [text.vshift.middlezero])
g.text(x1-.6, y1-.1, r"$E_{\rm b}$", [text.halign.right])
g.text(x3+.15, y2+.20, r"$2J_k(\varepsilon/\Omega)+\pi\gamma k\Omega$")
示例#5
0
        1 - x) + x**4


def blue(x):
    return 5 * x * (1 - x)**5 - 0.5 * x**2 * (1 - x)**3 + 0.3 * x * x * (
        1 - x)**2 + 5 * x**3 * (1 - x)**2 + 0.5 * x**6


# use the implemented converter for the grey value:
def grey(x):
    return color.rgb(red(x), green(x), blue(x)).grey().color["gray"]


# plot the color values
g = graph.graphxy(width=10, ratio=1)
g.plot(data.function("y(x)=red(x)", min=0, max=1, context=locals()),
       [graph.style.line([color.rgb.red])])
g.plot(data.function("y(x)=green(x)", min=0, max=1, context=locals()),
       [graph.style.line([color.rgb.green])])
g.plot(data.function("y(x)=blue(x)", min=0, max=1, context=locals()),
       [graph.style.line([color.rgb.blue])])
g.plot(data.function("y(x)=grey(x)", min=0, max=1, context=locals()))

# plot the colors
n = 200
x = 0
for i in range(n):
    t = i * 1.0 / (n - 1)
    g.fill(path.rect(x, -2, 10.5 / (n - 1), 1),
           [color.rgb(red(t), green(t), blue(t))])
    x += 10.0 / n
示例#6
0
range = 2.5

p = painter.regular(basepathattrs=[earrow.normal], titlepos=0.95,
                    outerticklength=painter.ticklength.normal,
                    titledist=-0.3, titledirection=None) # horizontal text

g = graphxy(width=10, xaxisat=0, yaxisat=0,
            x=axis.linear(title="$x$", min=-range, max=+range, painter=p,
                          # suppress some ticks by overwriting ...
                          manualticks=[tick.tick(0, None, None),
                                       tick.tick(range, None, None)]),
            y=axis.linear(title=r"$x\sin(x^2)$", painter=p,
                          manualticks=[tick.tick(0, None, None),
                                       tick.tick(3, None, None)]))

g.plot(data.function("y(x)=x*sin(x**2)"),
       # Line style is set before symbol style -> symbols will be draw
       # above the line.
       [graph.style.line([style.linewidth.Thin, style.linestyle.solid]),
        graph.style.symbol(graph.style.symbol.circle, size=0.1,
                           symbolattrs=[deco.filled([color.rgb.green]),
                                        deco.stroked([color.rgb.red])])])

# manually typeset "0" near the origin
g.dolayout()
x0, y0 = g.pos(0, 0)
g.text(x0 - 0.2, y0 - 0.2, "0", [text.halign.right, text.valign.top])

g.writeEPSfile("symbolline")
g.writePDFfile("symbolline")