コード例 #1
0
def set_myattrs(n, nhl):
    normalcolor = color.hsb(0.66, 1, 0.6)
    highlight = color.hsb(0, 1, 0.6)
    if n == nhl:
        return [highlight]
    else:
        return [normalcolor]
コード例 #2
0
def make_stride_figure(c, lowerstride, uperstride=1, nrentries=6):
    ht = 0.5
    wd = 2
    dist = 0.2
    textcolor = color.hsb(0.02, 1, 0.6)
    for n in range(nrentries):
        x = n*(wd+dist)
        c.stroke(path.rect(x, 0, wd, ht))
        c.text(x+0.5*wd, 0.5*ht, str(n), [text.halign.center, text.valign.middle])

    for n in range(nrentries-1):
        x = n*(wd+dist)
        c.stroke(path.curve(x-dist/3, ht+0.5*dist,
                            x+0.3*wd, ht+3*dist,
                            x+0.7*wd, ht+3*dist,
                            x+wd+dist/3, ht+0.5*dist),
                 [deco.earrow.large])
        c.text(x+0.5*wd, ht+3.2*dist, r'\Large 8', [text.halign.center, textcolor])

    if lowerstride:
        for n in range((nrentries-1)//lowerstride):
            x = n*lowerstride*(wd+dist)
            c.stroke(path.curve(x-dist/3, -0.5*dist,
                                x+0.5*wd, -5*dist,
                                x+(lowerstride-0.5)*wd+lowerstride*dist, -5*dist,
                                x+lowerstride*wd+(lowerstride-0.7)*dist, -0.5*dist),
                     [deco.earrow.large])
            c.text(x+0.5*lowerstride*wd+dist,-5.2*dist, r'\Large %i' % (lowerstride*8),
                   [text.halign.center, text.valign.top, textcolor])
コード例 #3
0
def make_stride_figure(c, lowerstride, uperstride=1, nrentries=6):
    ht = 0.5
    wd = 2
    dist = 0.2
    textcolor = color.hsb(0.02, 1, 0.6)
    for n in range(nrentries):
        x = n * (wd + dist)
        c.stroke(path.rect(x, 0, wd, ht))
        c.text(x + 0.5 * wd, 0.5 * ht, str(n),
               [text.halign.center, text.valign.middle])

    for n in range(nrentries - 1):
        x = n * (wd + dist)
        c.stroke(
            path.curve(x - dist / 3, ht + 0.5 * dist, x + 0.3 * wd,
                       ht + 3 * dist, x + 0.7 * wd, ht + 3 * dist,
                       x + wd + dist / 3, ht + 0.5 * dist),
            [deco.earrow.large])
        c.text(x + 0.5 * wd, ht + 3.2 * dist, r'\Large 8',
               [text.halign.center, textcolor])

    if lowerstride:
        for n in range((nrentries - 1) // lowerstride):
            x = n * lowerstride * (wd + dist)
            c.stroke(
                path.curve(x - dist / 3, -0.5 * dist, x + 0.5 * wd, -5 * dist,
                           x + (lowerstride - 0.5) * wd + lowerstride * dist,
                           -5 * dist,
                           x + lowerstride * wd + (lowerstride - 0.7) * dist,
                           -0.5 * dist), [deco.earrow.large])
            c.text(x + 0.5 * lowerstride * wd + dist, -5.2 * dist,
                   r'\Large %i' % (lowerstride * 8),
                   [text.halign.center, text.valign.top, textcolor])
コード例 #4
0
ファイル: NucCanvas.py プロジェクト: mpmendenhall/MPMUtils
 def HLcolor(self, t):
     """Half-life color scheme"""
     if (type(t) != type(1.0) and type(t) != type(1)) or t == 0: return rgb(.5, .5, .5)
     if t == float("inf"): return rgb.black
     x = log(t/self.HLmin)/log(pi*self.HLmax/self.HLmin) if t else 1
     x = min(max(0,x),1)
     return hsb(0.90*x, 1, 1)
コード例 #5
0
 def draw(self):
     p = path.path(path.moveto(*self.corners[0]),
                   path.lineto(*self.corners[1]),
                   path.lineto(*self.corners[2]),
                   path.lineto(*self.corners[3]),
                   path.closepath())
     fillcolor = color.hsb(2/3*(1-(self.counter-1)/(self.nsquares-1)), 0.2, 1)
     self.c.stroke(p, [deco.filled([fillcolor])])
     x, y = 0.5*(self.corners[0]+self.corners[2])
     s = int(np.sum(np.abs(self.corners[1]-self.corners[0])))
     self.c.text(x, y, str(s),
                 [text.halign.center, text.valign.middle,
                  text.size(min(s, 5))])
     self.counter = self.counter+1
コード例 #6
0
 def draw(self):
     p = path.path(path.moveto(*self.corners[0]),
                   path.lineto(*self.corners[1]),
                   path.lineto(*self.corners[2]),
                   path.lineto(*self.corners[3]), path.closepath())
     fillcolor = color.hsb(
         2 / 3 * (1 - (self.counter - 1) / (self.nsquares - 1)), 0.2, 1)
     self.c.stroke(p, [deco.filled([fillcolor])])
     x, y = 0.5 * (self.corners[0] + self.corners[2])
     s = int(np.sum(np.abs(self.corners[1] - self.corners[0])))
     self.c.text(
         x, y, str(s),
         [text.halign.center, text.valign.middle,
          text.size(min(s, 5))])
     self.counter = self.counter + 1
コード例 #7
0
def arraygraphics(a,
                  idxstr,
                  title=True,
                  xscale=1.0,
                  fgcolor=color.grey(1),
                  bgcolor=color.hsb(0.9, 1, 0.5)):
    """create a graphical representation of a two-dimensional array
    
    a         array containing the data to be shown
    slicestr  string defining the slice to be highlighted
    xscale    PyX scaling for text
    fgcolor   color of highlighted data
    bgcolor   color of highlighted cells

    """
    assert a.ndim == 2
    n0, n1 = a.shape
    highlighted = np.zeros_like(a, dtype=bool)
    exec("highlighted{} = True".format(idxstr))
    unit.set(xscale=xscale)
    text.set(text.LatexRunner)
    text.preamble(
        r'\usepackage[sfdefault,scaled=.85,lining]{FiraSans}\usepackage{newtxsf}'
    )
    c = canvas.canvas()
    for ny, nx in zip(*np.nonzero(highlighted)):
        c.fill(path.rect(nx, n0 - ny, 1, -1), [bgcolor])
    c.stroke(path.rect(0, 0, n1, n0))
    for nx in range(1, n1):
        c.stroke(path.line(nx, 0, nx, n0))
    for ny in range(1, n0):
        c.stroke(path.line(0, ny, n1, ny))
    textcentered = [text.halign.center, text.valign.middle]
    textcentered_highlighted = textcentered + [fgcolor]
    for nx in range(n1):
        for ny in range(n0):
            if highlighted[ny, nx]:
                textattrs = textcentered_highlighted
            else:
                textattrs = textcentered
            c.text(nx + 0.5, n0 - ny - 0.5, a[ny, nx], textattrs)
    if title:
        textcolor = bgcolor
    else:
        textcolor = color.grey(1)
    titlestr = r"\Large a" + idxstr.replace('%', '\%')
    c.text(0.5 * n1, n0 + 0.4, titlestr, [text.halign.center, textcolor])
    return c
コード例 #8
0
def arraygraphics(a, idxstr, title=True, xscale=1.0,
               fgcolor=color.grey(1), bgcolor=color.hsb(0.9, 1, 0.5)):
    """create a graphical representation of a two-dimensional array
    
    a         array containing the data to be shown
    slicestr  string defining the slice to be highlighted
    xscale    PyX scaling for text
    fgcolor   color of highlighted data
    bgcolor   color of highlighted cells

    """
    assert a.ndim == 2
    n0, n1 = a.shape
    highlighted = np.zeros_like(a, dtype=bool)
    exec("highlighted{} = True".format(idxstr))
    unit.set(xscale=xscale)
    text.set(text.LatexRunner)
    text.preamble(r'\usepackage[sfdefault,scaled=.85,lining]{FiraSans}\usepackage{newtxsf}')
    c = canvas.canvas()
    for ny, nx in zip(*np.nonzero(highlighted)):
        c.fill(path.rect(nx, n0-ny, 1, -1), [bgcolor])
    c.stroke(path.rect(0, 0, n1, n0))
    for nx in range(1, n1):
        c.stroke(path.line(nx, 0, nx, n0))
    for ny in range(1, n0):
        c.stroke(path.line(0, ny, n1, ny))
    textcentered = [text.halign.center, text.valign.middle]
    textcentered_highlighted = textcentered+[fgcolor]
    for nx in range(n1):
        for ny in range(n0):
            if highlighted[ny, nx]:
                textattrs = textcentered_highlighted
            else:
                textattrs = textcentered
            c.text(nx+0.5, n0-ny-0.5, a[ny, nx], textattrs)
    if title:
        textcolor = bgcolor
    else:
        textcolor = color.grey(1)
    titlestr = r"\Large a"+idxstr.replace('%', '\%')
    c.text(0.5*n1, n0+0.4, titlestr, [text.halign.center, textcolor])
    return c
コード例 #9
0
    c.stroke(path.line(1.5*x1+fak*(x2-x1), 1.5*y1+fak*(y2-y1),
                       1.5*x2-fak*(x2-x1), 1.5*y2-fak*(y2-y1)), 
               [arrowcolor, deco.earrow.Large, deco.barrow.Large, style.linewidth.THIck])

dy = 0.8
dx = 1.5
versionoff = 1.5
cf = canvas.canvas()
hueoff = 0.17
nr_revisions = 0
for nr, (name, versions) in enumerate((('file 1', (0, 2, 4, 5)),
                                       ('file 2', (0, 1, 2, 3, 5)),
                                       ('file 3', (1, 4, 5)))):
    nr_revisions = max(nr_revisions, max(versions))
    hue = hueoff+nr/3
    cf.text(0, -nr*dy, name, [color.hsb(hue, 1, 0.5), text.valign.middle])
    for nver, (v1, v2) in enumerate(zip(versions[:-1], versions[1:])):
        y = -(nr+0.4)*dy
        lv = len(versions)-1
        xll = v1*dx+versionoff+0.1
        yll = y
        width = (v2-v1)*dx-0.2
        height = 0.8*dy
        cf.fill(path.rect(xll, yll, width, height),
                [color.hsb(hue, 1-(lv-1-nver)/(lv-1)*0.7, 0.6)])
        cf.text(xll+0.5*width, yll+0.5*height, gethashstring(),
                [text.size(-4), text.halign.center, text.valign.middle, color.grey(1)])
for n in range(nr_revisions):
    xcenter = (n+0.5)*dx+versionoff
    y = 0.5
    cf.text(xcenter, y, gethashstring(), [text.size(-4), text.halign.center])
コード例 #10
0
import numpy as np
import numpy.polynomial.polynomial as P

from pyx import color, deco, graph, style, text, unit

np.random.seed(987)
x = np.pi*np.linspace(0, 1, 100)
y = np.sin(x)+0.1*np.random.rand(100)
fit = P.Polynomial(P.polyfit(x, y, 2))

text.set(text.LatexRunner)
text.preamble(r'\usepackage[sfdefault,scaled=.85,lining]{FiraSans}\usepackage{newtxsf}')
unit.set(xscale=1.2)

g = graph.graphxy(width=8,
        x=graph.axis.lin(title=r'\Large $x$', divisor=np.pi,
            texter=graph.axis.texter.rational(suffix=r'\pi')),
        y=graph.axis.lin(min=0, max=1.1, title=r'\Large $y$',
            parter=graph.axis.parter.lin(tickdists=[0.2])))
origdata = list(zip(x, y))
symbolattrs = [deco.filled, color.hsb(0.6, 1, 0.7)]
g.plot(graph.data.points(origdata, x=1, y=2),
       [graph.style.symbol(graph.style.symbol.circle, 0.07,
                           symbolattrs=symbolattrs)])
fitdata = list(zip(x, fit(x)))
lineattrs = [color.hsb(0.05, 1, 0.7), style.linewidth.THick]
g.plot(graph.data.points(fitdata, x=1, y=2),
       [graph.style.line(lineattrs=lineattrs)])
g.writePDFfile()
コード例 #11
0
ファイル: fig_aging_aero_tau.py プロジェクト: zzheng93/partmc
    for (key, y_data) \
            in [("num_low_cond", num_low_cond),
                ("num_low", num_low),
                ("num_mid_cond", num_mid_cond),
                ("num_mid", num_mid),
                ("num_high_cond", num_high_cond),
                ("num_high", num_high),
                ("mass_low_cond", mass_low_cond),
                ("mass_low", mass_low),
                ("mass_mid_cond", mass_mid_cond),
                ("mass_mid", mass_mid),
                ("mass_high_cond", mass_high_cond),
                ("mass_high", mass_high)]:
        g = graphs[plot_info[key]["graph"]]
        if use_color:
            grey_color = color.hsb(plot_info[key]["color"].hsb().color["h"],
                                   plot_info[key]["grey_level"], 1)
            style_attrs = [plot_info[key]["linewidth"], grey_color]
        else:
            grey_color = color.grey(1 - plot_info[key]["grey_level"])
            style_attrs = [plot_info[key]["linewidth"], grey_color]
        plot_data = zip(time[1:] / 60, y_data)
        g.plot(graph.data.points(plot_data, x=1, y=2),
               styles=[graph.style.line(lineattrs=style_attrs)])

    for (key, y_data) \
            in [("num_low_cond", num_low_cond_smooth),
                ("num_low", num_low_smooth),
                ("num_mid_cond", num_mid_cond_smooth),
                ("num_mid", num_mid_smooth),
                ("num_high_cond", num_high_cond_smooth),
                ("num_high", num_high_smooth),
コード例 #12
0
ファイル: PyxUtils.py プロジェクト: jpbrodsky/MPMUtils
def rainbow(n, b=1.0):
    """Rainbow color range"""
    return [ hsb((1.0*x)/n,1,b) for x in range(n) ]
コード例 #13
0
def rainbowDict(keys, b=1.0):
    """Rainbow colors assigned to sorted keys"""
    n = len(keys)
    knew = [k for k in keys]
    knew.sort()
    return dict([(k, hsb((1.0 * x) / n, 1, b)) for (x, k) in enumerate(knew)])
コード例 #14
0
c.stroke(path.line(0, 0.4 * h, w, 0.4 * h), [deco.earrow])
c.stroke(path.line(0, 0, 0, h), [deco.earrow])
with open('parrondo.dat') as file:
    dataset = file.readlines()

data = [tuple(map(int, line.strip('\n').split())) for line in dataset]
scale = lambda x: ((x + 1000) / 2500) * h
datascaled = [tuple(map(scale, x)) for x in data]
p1 = path.path(path.moveto(0, 0.4 * h))
p2 = path.path(path.moveto(0, 0.4 * h))
p3 = path.path(path.moveto(0, 0.4 * h))
for n, (a, b, aabb) in enumerate(datascaled):
    p1.append(path.lineto(w * n / 1000, a))
    p2.append(path.lineto(w * n / 1000, b))
    p3.append(path.lineto(w * n / 1000, aabb))
c.stroke(p1, [color.rgb(1, 0, 0)])
c.stroke(p2, [color.rgb(0, 1, 0)])
c.stroke(p3, [color.rgb(0, 0, 1)])

c1 = canvas.canvas()
c1.fill(path.circle(0, 0, 0.08 * w), [color.hsb(0.1, 1, 0.6)])
c1.text(0, 0, r'\Large\textit{\bfseries 1}',
        [text.halign.center, text.valign.middle,
         color.hsb(0.1, 1, 1)])
c1.fill(path.circle(0.18 * w, 0, 0.08 * w), [color.hsb(0.1, 1, 0.6)])
c1.text(0.18 * w, 0, r'\Large\Smiley',
        [text.halign.center, text.valign.middle,
         color.hsb(0.1, 1, 1)])
c.insert(c1, [trafo.translate(0.1 * w, 0.8 * h)])
c.writeGSfile(device="png16m", resolution=300)
コード例 #15
0
ファイル: polynomial.py プロジェクト: papadopa-cy/jupyter4edu
text.preamble(r'''\usepackage[scaled=0.85,lining]{FiraMono}
                  \usepackage[utf8]{inputenc}''')
unit.set(xscale=1.2)

c = canvas.canvas()
dx = 0.3
h = 4
w = 6.5
p = path.rect(-dx, -dx, w+2*dx, h+2*dx)
p = deformer.smoothed(0.5).deform(p)
c.fill(p, [color.grey(0.5), trafo.translate(0.05, -0.05)])
c.fill(p, [color.grey(0.9)])

c1 = canvas.canvas([canvas.clip(p)])
c2 = canvas.canvas()
textcolor = color.hsb(0.6, 0.3, 1)
t = """\Huge
$2x^4+10x^3$

p1 = \{4: 2, 3: 10\}

$5x^2-x+32$

p2 = \{2: 5, 1: -1, 0: 32\}

multiply(p1, p2)
"""
c2.text(0, 0, t, [text.parbox(2*w), textcolor])
c1.insert(c2, [trafo.rotate(20).translated(-0.2*w, 0.9*h)])
c.insert(c1)
コード例 #16
0
from pyx import canvas, color, deformer, path, text, trafo, unit

text.set(text.LatexRunner)
text.preamble(r'''\usepackage[scaled=0.85,lining]{FiraMono}
                  \usepackage[utf8]{inputenc}''')
pistring = '3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852'
char_per_line = 25
pistring = ' '.join(
    [pistring[n * char_per_line:(n + 1) * char_per_line] for n in range(10)])
unit.set(xscale=1.45)

c = canvas.canvas()
dx = 0.3
h = 4
w = 6.5
p = path.rect(-dx, -dx, w + 2 * dx, h + 2 * dx)
p = deformer.smoothed(0.5).deform(p)
c.fill(p, [color.grey(0.5), trafo.translate(0.05, -0.05)])
c.fill(p, [color.grey(0.9)])
c.text(0, 0, r'\noindent\texttt{{{}}}'.format(pistring),
       [text.valign.bottom, text.parbox(5)])
c.text(0.5 * w, 0.5 * h, r'\Huge $\pi$', [
    text.halign.center, text.valign.middle,
    color.hsb(0.66, 0.8, 1),
    color.transparency(0.2),
    trafo.scale(5.8)
])

c.writePDFfile()
コード例 #17
0
p = path.rect(-dx, -dx, w + 2 * dx, h + 2 * dx)
p = deformer.smoothed(0.5).deform(p)
c.fill(p, [color.grey(0.5), trafo.translate(0.05, -0.05)])
c.fill(p, [color.grey(0.9)])

c2 = canvas.canvas([canvas.clip(p)])
primetimes = [p for p in prime_list(2359) if is_time(p)]
s = text.text(0, 0, formattime(primetimes[0]))
textwidth, textheight = s.width, s.height
nx = int(w / unit.tocm(textwidth))
xoff = 0.5 * (w - 1.2 * textwidth * nx + 0.2 * textwidth)
for n, p in enumerate(primetimes):
    s = formattime(p)
    x = xoff + (n % nx) * 1.2 * textwidth
    y = 1.03 * h - (n // nx) * textheight * 1.4
    c2.text(x, y, s, [color.hsb(0.67, 0.4, 0.8)])
c.insert(c2)

r1 = 0.95 * h / 2
r2 = 0.8 * h / 2
for n in range(12):
    x = sin(radians(n * 30))
    y = cos(radians(n * 30))
    c.stroke(
        path.line(w / 2 + r1 * x, h / 2 + r1 * y, w / 2 + r2 * x,
                  h / 2 + r2 * y), [style.linewidth.THICk])
x = sin(radians(70))
y = cos(radians(70))
c.stroke(
    path.line(w / 2 - 0.1 * x, h / 2 - 0.1 * y, w / 2 + r1 * x,
              h / 2 + r1 * y),
コード例 #18
0
                  path.arcn(0.1, 0, 0.1, 160, 0))
    cwrite.stroke(
        p, [color,
            trafo.scale(size).rotated(-30).translated(0, -0.4 * size)])
    return cwrite


text.set(text.LatexRunner)
text.preamble(r'\usepackage{arev}\usepackage[T1]{fontenc}')
c = canvas.canvas()

wd = 6.9
ht = 3.5
gitlabfgcolor = color.grey(0.4)
gitlabbgcolor = color.grey(0.97)
maintainercolor = color.hsb(0.7, 1, 0.5)
usercolor = color.hsb(0.05, 1, 0.5)
c.stroke(path.rect(0, 0, wd, ht), [
    deformer.smoothed(0.1), gitlabfgcolor, style.linewidth.Thick,
    deco.filled([gitlabbgcolor])
])

clabel = canvas.canvas()
labeltext = text.text(0, 0, r'\textsf{\bfseries Gitlab}', [color.grey(1)])
extrawd = 0.15
labelbox = labeltext.bbox().enlarged(extrawd)
clabel.fill(labelbox.path(), [gitlabfgcolor, deformer.smoothed(0.1)])
clabel.insert(labeltext)
c.insert(clabel, [trafo.translate(extrawd, ht + extrawd)])

c.text(wd + 0.4, ht - 0.5, r'\footnotesize\textsf{read/write permissions}')
コード例 #19
0
def rainbow(n):
    return [ hsb((1.0*x)/n,1,1) for x in range(n) ]
コード例 #20
0
        inner_offset = framefactor*boxsize
    p = (path.rect(x+outer_offset, y+outer_offset,
                   w-2*outer_offset, h-2*outer_offset)
         + path.rect(x+inner_offset, y+inner_offset,
                     w-2*inner_offset, h-2*inner_offset).reversed()
         )
    c.fill(p, [framecolor])


ncols = 6
nrows = ncols
boxsize = 1
angle = radians(40)
reducedboxsize = 0.65*boxsize

ex1color = color.hsb(0, 1, 0.7)
ex2color = color.hsb(0.28, 1, 0.5)
ex3color = color.hsb(0.56, 1, 0.6)
ex4color = color.hsb(0.84, 1, 0.6)

text.set(text.LatexRunner)
preamble = r'''\usepackage[T1]{fontenc}
               \usepackage{bera}
               \renewcommand*\familydefault{\ttdefault}
               \usepackage{color}'''
for nr, elem in enumerate((ex1color, ex2color, ex3color, ex4color)):
    preamble = preamble+r'\definecolor{{ex{}color}}{{hsb}}{{{}, {}, {}}}'.format(
                  nr+1, elem.h, elem.s, elem.b)
text.preamble(preamble)
unit.set(xscale=1.2)
コード例 #21
0
    return cf


text.set(text.LatexRunner)
text.preamble(r'\usepackage{arev}\usepackage[T1]{fontenc}')

c = canvas.canvas()
ht = 5
htlabel = 1
wd = 3.5
vdist = 0.05
hdist = 1
size = 1.2

for nr, (label, boxcolor, symbolcolor, status) in enumerate(
    (('working directory', color.hsb(0.87, 1, 0.6), color.rgb(0.6, 0,
                                                              0), 'modified'),
     ('staging area', color.hsb(0.2, 1, 0.6), color.rgb(0, 0.5, 0), 'staged'),
     ('repository (.git)', color.hsb(0.53, 1,
                                     0.6), color.grey(0.3), 'committed'))):
    xmid = nr * (wd + hdist) + 0.5 * wd
    c.stroke(path.rect(nr * (wd + hdist), 0, wd, ht),
             [deformer.smoothed(0.3), boxcolor, style.linewidth.Thick])
    c.fill(path.rect(nr * (wd + hdist), ht + vdist, wd, htlabel),
           [deformer.smoothed(0.3), boxcolor])
    c.text(xmid, ht + vdist + 0.5 * htlabel, label,
           [text.halign.center, text.valign.middle,
            color.grey(1)])
    c.insert(filesymbol(size, symbolcolor), [trafo.translate(xmid, 0.5 * ht)])
    c.text(xmid, 0.2 * ht, status, [text.halign.center, symbolcolor])
for nr, operation in enumerate(('git add', 'git commit')):
コード例 #22
0
    clist.append((nx, ny, c[nx * nlen:(nx + 1) * nlen,
                            ny * nlen:(ny + 1) * nlen]))
ex = futures.ProcessPoolExecutor(max_workers=4)
results = list(ex.map(partial(mandelbrot_iteration, niter), clist))

data = []
procdict = {}
for r in results:
    nx, ny, procid, partialdata = r
    for mx, my in product(range(nlen), repeat=2):
        cval = c[nx * nlen + mx, ny * nlen + my]
        data.append((cval.real, cval.imag, partialdata[mx, my]))
    procdict[(nx, ny)] = procid
procids = set(procdict.values())
colors = [
    color.hsb(n / (len(procids) - 1) * 0.67, 1, 1) for n in range(len(procids))
]
proccolors = dict(zip(procids, colors))

text.set(text.LatexRunner)
text.preamble(r'\usepackage{arev}\usepackage[T1]{fontenc}')
g = graph.graphxy(width=8,
                  height=8,
                  x=graph.axis.lin(title=r'$\mathrm{Re}(c)$'),
                  y=graph.axis.lin(title=r'$\mathrm{Im}(c)$'))
g.plot(graph.data.points(data, x=1, y=2, color=3),
       [graph.style.density(keygraph=None)])

dx = (xmax - xmin) / n
dy = (ymax - ymin) / n
for k, v in procdict.items():
コード例 #23
0
ファイル: dvifile.py プロジェクト: atal2003/test
    def special(self, s, fontmap):
        x = self.pos[_POS_H] * self.pyxconv
        y = -self.pos[_POS_V] * self.pyxconv
        if self.debug:
            self.debugfile.write("%d: xxx '%s'\n" % (self.filepos, s))
        if not s.startswith("PyX:"):
            logger.warning("ignoring special '%s'" % s)
            return

        # it is in general not safe to continue using the currently active font because
        # the specials may involve some gsave/grestore operations
        self.flushtext(fontmap)

        command, args = s[4:].split()[0], s[4:].split()[1:]
        if command == "color_begin":
            if args[0] == "cmyk":
                c = color.cmyk(float(args[1]), float(args[2]), float(args[3]),
                               float(args[4]))
            elif args[0] == "gray":
                c = color.gray(float(args[1]))
            elif args[0] == "hsb":
                c = color.hsb(float(args[1]), float(args[2]), float(args[3]))
            elif args[0] == "rgb":
                c = color.rgb(float(args[1]), float(args[2]), float(args[3]))
            elif args[0] == "RGB":
                c = color.rgb(
                    int(args[1]) / 255.0,
                    int(args[2]) / 255.0,
                    int(args[3]) / 255.0)
            elif args[0] == "texnamed":
                try:
                    c = getattr(color.cmyk, args[1])
                except AttributeError:
                    raise RuntimeError("unknown TeX color '%s', aborting" %
                                       args[1])
            elif args[0] == "pyxcolor":
                # pyx.color.cmyk.PineGreen or
                # pyx.color.cmyk(0,0,0,0.0)
                pat = re.compile(
                    r"(pyx\.)?(color\.)?(?P<model>(cmyk)|(rgb)|(grey)|(gray)|(hsb))[\.]?(?P<arg>.*)"
                )
                sd = pat.match(" ".join(args[1:]))
                if sd:
                    sd = sd.groupdict()
                    if sd["arg"][0] == "(":
                        numpat = re.compile(
                            r"[+-]?((\d+\.\d*)|(\d*\.\d+)|(\d+))([eE][+-]\d+)?"
                        )
                        arg = tuple(
                            [float(x[0]) for x in numpat.findall(sd["arg"])])
                        try:
                            c = getattr(color, sd["model"])(*arg)
                        except TypeError or AttributeError:
                            raise RuntimeError(
                                "cannot access PyX color '%s' in TeX, aborting"
                                % " ".join(args[1:]))
                    else:
                        try:
                            c = getattr(getattr(color, sd["model"]), sd["arg"])
                        except AttributeError:
                            raise RuntimeError(
                                "cannot access PyX color '%s' in TeX, aborting"
                                % " ".join(args[1:]))
                else:
                    raise RuntimeError(
                        "cannot access PyX color '%s' in TeX, aborting" %
                        " ".join(args[1:]))
            else:
                raise RuntimeError(
                    "color model '%s' cannot be handled by PyX, aborting" %
                    args[0])

            self.beginsubpage([c])
        elif command == "color_end":
            self.endsubpage()
        elif command == "rotate_begin":
            self.beginsubpage([trafo.rotate_pt(float(args[0]), x, y)])
        elif command == "rotate_end":
            self.endsubpage()
        elif command == "scale_begin":
            self.beginsubpage(
                [trafo.scale_pt(float(args[0]), float(args[1]), x, y)])
        elif command == "scale_end":
            self.endsubpage()
        elif command == "epsinclude":
            # parse arguments
            argdict = {}
            for arg in args:
                name, value = arg.split("=")
                argdict[name] = value

            # construct kwargs for epsfile constructor
            epskwargs = {}
            epskwargs["filename"] = argdict["file"]
            epskwargs["bbox"] = bbox.bbox_pt(float(argdict["llx"]),
                                             float(argdict["lly"]),
                                             float(argdict["urx"]),
                                             float(argdict["ury"]))
            if "width" in argdict:
                epskwargs["width"] = float(argdict["width"]) * unit.t_pt
            if "height" in argdict:
                epskwargs["height"] = float(argdict["height"]) * unit.t_pt
            if "clip" in argdict:
                epskwargs["clip"] = int(argdict["clip"])
            self.actpage.insert(
                epsfile.epsfile(x * unit.t_pt, y * unit.t_pt, **epskwargs))
        elif command == "marker":
            if len(args) != 1:
                raise RuntimeError("marker contains spaces")
            for c in args[0]:
                if c not in string.ascii_letters + string.digits + "@":
                    raise RuntimeError("marker contains invalid characters")
            if args[0] in self.actpage.markers:
                raise RuntimeError("marker name occurred several times")
            self.actpage.markers[args[0]] = x * unit.t_pt, y * unit.t_pt
        else:
            raise RuntimeError("unknown PyX special '%s', aborting" % command)
コード例 #24
0
        outer_offset = 0
        inner_offset = framefactor * boxsize
    p = (path.rect(x + outer_offset, y + outer_offset, w - 2 * outer_offset,
                   h - 2 * outer_offset) +
         path.rect(x + inner_offset, y + inner_offset, w - 2 * inner_offset,
                   h - 2 * inner_offset).reversed())
    c.fill(p, [framecolor])


ncols = 6
nrows = ncols
boxsize = 1
angle = radians(40)
reducedboxsize = 0.65 * boxsize

ex1color = color.hsb(0, 1, 0.7)
ex2color = color.hsb(0.28, 1, 0.5)
ex3color = color.hsb(0.56, 1, 0.6)
ex4color = color.hsb(0.84, 1, 0.6)

text.set(text.LatexRunner)
preamble = r'''\usepackage[T1]{fontenc}
               \usepackage{bera}
               \renewcommand*\familydefault{\ttdefault}
               \usepackage{color}'''
for nr, elem in enumerate((ex1color, ex2color, ex3color, ex4color)):
    preamble = preamble + r'\definecolor{{ex{}color}}{{hsb}}{{{}, {}, {}}}'.format(
        nr + 1, elem.h, elem.s, elem.b)
text.preamble(preamble)
unit.set(xscale=1.2)
コード例 #25
0
from pyx import canvas, color, path, text, unit

text.set(text.LatexRunner)
text.preamble(
    r'\usepackage{arev}\usepackage[T1]{fontenc}\usepackage{nicefrac}')
unit.set(xscale=1.2, wscale=1.2)

c = canvas.canvas()
side = 4
lightcolor = color.hsb(0.65, 0.2, 1)
darkcolor = color.hsb(0.65, 1, 1)
c.fill(
    path.path(path.moveto(0, 0), path.lineto(side, 0),
              path.arc(0, 0, side, 0, 90), path.closepath()), [lightcolor])
c.stroke(path.path(path.arc(0, 0, side, 0, 90)), [darkcolor])
c.stroke(path.rect(0, 0, side, side))
ticklen = 0.15
for tick in (0, 1):
    dist = tick * side
    c.stroke(path.line(dist, 0, dist, -ticklen))
    c.text(dist, -1.5 * ticklen, str(tick),
           [text.halign.center, text.valign.top])
    c.stroke(path.line(0, dist, -ticklen, dist))
    c.text(-1.5 * ticklen, dist, str(tick),
           [text.halign.right, text.valign.middle])
c.text(0.4 * side, 0.4 * side, r'\huge$\nicefrac{\pi}{4}$',
       [text.halign.center, text.valign.middle, darkcolor])
c.writePDFfile()
コード例 #26
0
xmin = -2
xmax = 1
width = npts
ymin = -1.5
ymax = 1.5
height = npts
niter = 2000

cnvs = canvas.canvas()
unit.set(wscale=0.8)
cellheight = 0.17

for nr, ndiv in enumerate((2, 4, 8, 16, 32)):
    nrproc, start, ende, data = mandelbrot(xmin, xmax, width, ymin, ymax, height,
                      npts, ndiv, niter)
    offset = -(nrproc+1.2)*cellheight*nr
    cnvs.text(-0.2, offset+2*cellheight, "$n=%s$" % ndiv**2,
              [text.halign.right, text.valign.middle])
    cnvs.stroke(path.line(0, -0.2*cellheight+offset, 0,
        (nrproc+0.2)*cellheight+offset))
    cnvs.stroke(path.line(ende-start, -0.2*cellheight+offset, ende-start,
        (nrproc+0.2)*cellheight+offset))
    for d in data:
        colours = color.hsb(0.667*d[0]/(nrproc-1), 1, 0.3)
        colourf = color.hsb(0.667*d[0]/(nrproc-1), 0.2, 1)
        cnvs.stroke(path.rect(d[1], d[0]*cellheight+offset, (d[2]-d[1]), 0.8*cellheight),
                [colours, deco.filled([colourf])])

cnvs.writePDFfile()
cnvs.writeGSfile(device="png16m", resolution=600)
コード例 #27
0
ファイル: dvifile.py プロジェクト: mjg/PyX-svn
    def special(self, s, fontmap):
        x =  self.pos[_POS_H] * self.pyxconv
        y = -self.pos[_POS_V] * self.pyxconv
        if self.debug:
            self.debugfile.write("%d: xxx '%s'\n" % (self.filepos, s))
        if not s.startswith("PyX:"):
            logger.warning("ignoring special '%s'" % s)
            return

        # it is in general not safe to continue using the currently active font because
        # the specials may involve some gsave/grestore operations
        self.flushtext(fontmap)

        command, args = s[4:].split()[0], s[4:].split()[1:]
        if command == "color_begin":
            if args[0] == "cmyk":
                c = color.cmyk(float(args[1]), float(args[2]), float(args[3]), float(args[4]))
            elif args[0] == "gray":
                c = color.gray(float(args[1]))
            elif args[0] == "hsb":
                c = color.hsb(float(args[1]), float(args[2]), float(args[3]))
            elif args[0] == "rgb":
                c = color.rgb(float(args[1]), float(args[2]), float(args[3]))
            elif args[0] == "RGB":
                c = color.rgb(int(args[1])/255.0, int(args[2])/255.0, int(args[3])/255.0)
            elif args[0] == "texnamed":
                try:
                    c = getattr(color.cmyk, args[1])
                except AttributeError:
                    raise RuntimeError("unknown TeX color '%s', aborting" % args[1])
            elif args[0] == "pyxcolor":
                # pyx.color.cmyk.PineGreen or
                # pyx.color.cmyk(0,0,0,0.0)
                pat = re.compile(r"(pyx\.)?(color\.)?(?P<model>(cmyk)|(rgb)|(grey)|(gray)|(hsb))[\.]?(?P<arg>.*)")
                sd = pat.match(" ".join(args[1:]))
                if sd:
                    sd = sd.groupdict()
                    if sd["arg"][0] == "(":
                        numpat = re.compile(r"[+-]?((\d+\.\d*)|(\d*\.\d+)|(\d+))([eE][+-]\d+)?")
                        arg = tuple([float(x[0]) for x in numpat.findall(sd["arg"])])
                        try:
                            c = getattr(color, sd["model"])(*arg)
                        except TypeError or AttributeError:
                            raise RuntimeError("cannot access PyX color '%s' in TeX, aborting" % " ".join(args[1:]))
                    else:
                        try:
                            c = getattr(getattr(color, sd["model"]), sd["arg"])
                        except AttributeError:
                            raise RuntimeError("cannot access PyX color '%s' in TeX, aborting" % " ".join(args[1:]))
                else:
                    raise RuntimeError("cannot access PyX color '%s' in TeX, aborting" % " ".join(args[1:]))
            else:
                raise RuntimeError("color model '%s' cannot be handled by PyX, aborting" % args[0])

            self.beginsubpage([c])
        elif command == "color_end":
            self.endsubpage()
        elif command == "rotate_begin":
            self.beginsubpage([trafo.rotate_pt(float(args[0]), x, y)])
        elif command == "rotate_end":
            self.endsubpage()
        elif command == "scale_begin":
            self.beginsubpage([trafo.scale_pt(float(args[0]), float(args[1]), x, y)])
        elif command == "scale_end":
            self.endsubpage()
        elif command == "epsinclude":
            # parse arguments
            argdict = {}
            for arg in args:
                name, value = arg.split("=")
                argdict[name] = value

            # construct kwargs for epsfile constructor
            epskwargs = {}
            epskwargs["filename"] = argdict["file"]
            epskwargs["bbox"] = bbox.bbox_pt(float(argdict["llx"]), float(argdict["lly"]),
                                           float(argdict["urx"]), float(argdict["ury"]))
            if "width" in argdict:
                epskwargs["width"] = float(argdict["width"]) * unit.t_pt
            if "height" in argdict:
                epskwargs["height"] = float(argdict["height"]) * unit.t_pt
            if "clip" in argdict:
               epskwargs["clip"] = int(argdict["clip"])
            self.actpage.insert(epsfile.epsfile(x * unit.t_pt, y * unit.t_pt, **epskwargs))
        elif command == "marker":
            if len(args) != 1:
                raise RuntimeError("marker contains spaces")
            for c in args[0]:
                if c not in string.ascii_letters + string.digits + "@":
                    raise RuntimeError("marker contains invalid characters")
            if args[0] in self.actpage.markers:
                raise RuntimeError("marker name occurred several times")
            self.actpage.markers[args[0]] = x * unit.t_pt, y * unit.t_pt
        else:
            raise RuntimeError("unknown PyX special '%s', aborting" % command)
コード例 #28
0
text.set(text.LatexRunner)
text.preamble(r'\usepackage{arev}\usepackage[T1]{fontenc}')
unit.set(xscale=1.3)

c = canvas.canvas()
pos = [(0, 1), (sin(2 * pi / 3), cos(2 * pi / 3)),
       (-sin(2 * pi / 3), cos(2 * pi / 3))]
sfak = 1.5
for x, y in pos:
    c.insert(server(0.3), [trafo.translate(sfak * x, sfak * y)])
    c.insert(client(), [trafo.scale(0.5).translated(3 * x, 3 * y + 0.15)])
    c.stroke(path.line(2.7 * x, 2.7 * y, 1.9 * x, 1.9 * y), [
        arrowcolor, deco.earrow.large, deco.barrow.large, style.linewidth.THick
    ])
for phi in (0, 120, 240):
    c.stroke(
        path.curve(-sfak * sin(2 * pi / 3) + 0.4, -0.5 * sfak + 0.15,
                   -sfak * sin(2 * pi / 3) + 0.8, -0.5 * sfak + 0.35,
                   sfak * sin(2 * pi / 3) - 0.8, -0.5 * sfak + 0.35,
                   sfak * sin(2 * pi / 3) - 0.4, -0.5 * sfak + 0.15), [
                       arrowcolor, deco.earrow.large, deco.barrow.large,
                       style.linewidth.THick,
                       trafo.rotate(phi)
                   ])
c.insert(server(0.5, color.hsb(0.5, 0.8, 0.5), 0.13))
c.text(0.8, 0.2, 'Gitlab / Github server',
       [color.hsb(0.5, 0.8, 0.5), text.size.small])

c.writePDFfile()
コード例 #29
0
def rainbowDict(keys, b=1.0):
    n = len(keys)
    knew = [k for k in keys]
    knew.sort()
    return dict([ (k,hsb((1.0*x)/n,1,b)) for (x,k) in enumerate(knew) ])
コード例 #30
0
from pyx import canvas, color, path, text, unit

text.set(text.LatexRunner)
text.preamble(r'\usepackage[sfdefault,scaled=.85,lining]{FiraSans}\usepackage{newtxsf}')
text.preamble(r'\usepackage{nicefrac}')
unit.set(xscale=1.6, wscale=1.2)

c = canvas.canvas()
side = 4
lightcolor = color.hsb(0.65, 0.2, 1)
darkcolor = color.hsb(0.65, 1, 1)
c.fill(path.path(path.moveto(0, 0),
                 path.lineto(side, 0),
                 path.arc(0, 0, side, 0, 90),
                 path.closepath()), [lightcolor])
c.stroke(path.path(path.arc(0, 0, side, 0, 90)), [darkcolor])
c.stroke(path.rect(0, 0, side, side))
ticklen = 0.15
for tick in (0, 1):
    dist = tick*side
    c.stroke(path.line(dist, 0, dist, -ticklen))
    c.text(dist, -1.5*ticklen, str(tick), [text.halign.center, text.valign.top])
    c.stroke(path.line(0, dist, -ticklen, dist))
    c.text(-1.5*ticklen, dist, str(tick), [text.halign.right, text.valign.middle])
c.text(0.4*side, 0.4*side, r'\huge$\nicefrac{\pi}{4}$',
       [text.halign.center, text.valign.middle, darkcolor])
c.writePDFfile()
コード例 #31
0
def rainbow(n, b=1.0):
    return [hsb((1.0 * x) / n, 1, b) for x in range(n)]
コード例 #32
0
def rainbow(n, b=1.0):
	return [ hsb((1.0*x)/n,1,b) for x in range(n) ]
コード例 #33
0
def rainbow(n, b=1.0):
    """Rainbow color range"""
    return [hsb((1.0 * x) / n, 1, b) for x in range(n)]
コード例 #34
0
def rainbowDict(keys, b=1.0):
	n = len(keys)
	knew = [k for k in keys]
	knew.sort()
	return dict([ (k,hsb((1.0*x)/n,1,b)) for (x,k) in enumerate(knew) ])
コード例 #35
0
ファイル: conway.py プロジェクト: papadopa-cy/jupyter4edu

c = canvas.canvas()
dx = 0.3
h = 4
w = 6.5
p = path.rect(-dx, -dx, w + 2 * dx, h + 2 * dx)
p = deformer.smoothed(0.5).deform(p)
c.fill(p, [color.grey(0.5), trafo.translate(0.05, -0.05)])

c1 = canvas.canvas([canvas.clip(p)])
c1.fill(p, [color.grey(0.9)])

np.random.seed = 42
game = Conway(300)
for _ in range(15):
    game.update()
world = game.world
xoff = -0.5 * w - dx
yoff = -0.5 * h - dx
delta = 0.1
for nx in range(game.size):
    for ny in range(game.size):
        if world[nx, ny]:
            p = path.rect(xoff + (nx + 0.1) * delta, yoff + (ny + 0.1) * delta,
                          0.8 * delta, 0.8 * delta)
            c1.fill(p, [color.hsb(0.25, 1, 0.5)])

c.insert(c1)
c.writeGSfile(device="png16m", resolution=300)
コード例 #36
0
basename = os.path.splitext(sys.argv[0])[0]
baseprimes = [0, 2, 3, 5, 7]
ncolor = len(baseprimes) - 1
cancelled = set([0, 1])
for nr, baseprime in enumerate(baseprimes):
    if nr == 0:
        for n in range(2, 50):
            x = n % 25
            y = 2 - (n // 25)
            c.text(x + 0.5, y - 0.5, str(n),
                   [text.halign.center, text.valign.middle])
    else:
        cancelled.add(baseprime)
        hvalue = 1.1 * (nr - 1) / (ncolor - 1)
        hvalue = hvalue - int(hvalue)
        primecolor = color.hsb(hvalue, 1, 0.8)
        x = baseprime % 25
        y = 2 - (baseprime // 25)
        c.fill(path.rect(x, y, 1, -1), [primecolor])
        c.text(x + 0.5, y - 0.5, r'\textbf{%s}' % baseprime,
               [text.halign.center, text.valign.middle,
                color.grey(1)])
        for n in range(baseprime**2, 50, baseprime):
            if not n in cancelled:
                cancelled.add(n)
                x = n % 25
                y = 2 - (n // 25)
                c.stroke(path.line(x, y - 1, x + 1, y), [primecolor])
                c.stroke(path.line(x, y, x + 1, y - 1), [primecolor])
    draw_grid()
    cc = canvas.canvas()
コード例 #37
0
ファイル: PyxUtils.py プロジェクト: jpbrodsky/MPMUtils
def rainbowDict(keys, b=1.0):
    """Rainbow colors assigned to sorted keys"""
    n = len(keys)
    knew = [k for k in keys]
    knew.sort()
    return dict([ (k,hsb((1.0*x)/n,1,b)) for (x,k) in enumerate(knew) ])
コード例 #38
0
c.text(1.5, 1.5, '1', [text.halign.center, text.valign.middle])
basename = os.path.splitext(sys.argv[0])[0]
baseprimes = [0, 2, 3, 5, 7]
ncolor = len(baseprimes)-1
cancelled = set([0, 1])
for nr, baseprime in enumerate(baseprimes):
    if nr == 0:
        for n in range(2, 50):
            x = n % 25
            y = 2-(n//25)
            c.text(x+0.5, y-0.5, str(n), [text.halign.center, text.valign.middle])
    else:
        cancelled.add(baseprime)
        hvalue = 1.1*(nr-1)/(ncolor-1)
        hvalue = hvalue-int(hvalue)
        primecolor = color.hsb(hvalue, 1, 0.8)
        x = baseprime % 25
        y = 2-(baseprime//25)
        c.fill(path.rect(x, y, 1, -1), [primecolor])
        c.text(x+0.5, y-0.5, r'\textbf{%s}' % baseprime,
               [text.halign.center, text.valign.middle, color.grey(1)])
        for n in range(baseprime**2, 50, baseprime):
            if not n in cancelled:
                cancelled.add(n)
                x = n % 25
                y = 2-(n//25)
                c.stroke(path.line(x, y-1, x+1, y), [primecolor])
                c.stroke(path.line(x, y, x+1, y-1), [primecolor])
    draw_grid()
    c.writePDFfile('%s_%s' % (basename, nr+1))