コード例 #1
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
コード例 #2
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
コード例 #3
0
#!/usr/bin/env python

import sys
import os

import numpy
from pyx import canvas, text, path, graph, color, trafo, unit, attr, deco, style, bitmap
import h5py

import hifive


unit.set(defaultunit="cm")
text.set(mode="latex")
text.preamble(r"\usepackage{times}")
text.preamble(r"\usepackage{sansmath}")
text.preamble(r"\sansmath")
text.preamble(r"\renewcommand*\familydefault{\sfdefault}")
painter = graph.axis.painter.regular( labeldist=0.1, labelattrs=[text.size(-3)], titleattrs=[text.size(-3)] )

methods = ['Raw', 'Prob', 'Exp', 'Bin', 'Exp-KR']
method_colors = {
        'Prob':color.cmyk.Black,
        'Exp':color.cmyk.CadetBlue,
        'Bin':color.cmyk.MidnightBlue, 
        'Raw':color.cmyk.Dandelion,
        'Exp-KR':color.cmyk.Mahogany,
}


def main():
コード例 #4
0
ファイル: decode.py プロジェクト: punkdit/fibonacci
#!/usr/bin/env python

import sys
from math import *
from random import *
import numpy

from pyx import canvas, path, deco, trafo, style, text, color, deformer

text.set(mode="latex") 
text.set(docopt="12pt")
text.preamble(r"\usepackage{amsmath,amsfonts,amssymb}")

rgb = color.rgb
rgbfromhexstring = color.rgbfromhexstring

red, green, blue, yellow = (
    rgbfromhexstring("#d00000"),
    rgbfromhexstring("#006000"),
    rgb.blue, rgb(0.75, 0.75, 0)) 

black = rgb(0., 0., 0.) 
blue = rgb(0., 0., 0.8)
lred = rgb(1., 0.4, 0.4)
white = rgb(1., 1., 1.) 

shade = rgb(0.75, 0.55, 0)
grey = rgb(0.75, 0.75, 0.75)

light_shade = rgb(0.85, 0.65, 0.1)
light_shade = rgb(0.9, 0.75, 0.4)
コード例 #5
0
from pyx import canvas, color, deco, 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.4, wscale=1.2)

c = canvas.canvas()
r = 0.05
for n in range(1, 5):
    c.stroke(path.circle(n, 0, r))
    c.stroke(path.circle(-n, 0, r))
c.stroke(path.circle(0, 0, r), [deco.filled([color.grey(0)])])
dx = 0.1
dy = 0.3
c.stroke(path.curve(dx, dx, dy, dy, 1-dy, dy, 1-dx, dx), [deco.earrow])
c.text(0.5, dy+0.1, '+1', [text.halign.center])
c.stroke(path.curve(-dx, dx, -dy, dy, -1+dy, dy, -1+dx, dx), [deco.earrow])
c.text(-0.5, dy+0.1, '-1', [text.halign.center])
c.writePDFfile()
コード例 #6
0
                   box.bottom() + pdy, xoff,
                   box.bottom() - pd))
    xoff = box.right() + pd
    c.stroke(
        path.curve(xoff,
                   box.top() + pd, xoff + pdx,
                   box.top() - pdy, xoff + pdx,
                   box.bottom() + pdy, xoff,
                   box.bottom() - pd))
    return c


text.set(text.LatexRunner)
color0 = color.rgb(0.8, 0, 0)
color1 = color.rgb(0, 0, 0.8)
text.preamble(r'\usepackage{arev}\usepackage[T1]{fontenc}')
text.preamble(r'\usepackage{color}')
text.preamble(r'\definecolor{axis0}{rgb}{%s, %s, %s}' %
              (color0.r, color0.g, color0.b))
text.preamble(r'\definecolor{axis1}{rgb}{%s, %s, %s}' %
              (color1.r, color1.g, color1.b))
unit.set(xscale=1.2, wscale=1.5)

c = canvas.canvas()
m1 = np.arange(4).reshape(2, 2)
c_m1 = matrix_22(m1)
m2 = np.arange(4, 8).reshape(2, 2)
c_m2 = matrix_22(m2)
m3 = np.dot(m1, m2)
c_m3 = matrix_22(m3, dx=0.7)
c.insert(c_m1)
コード例 #7
0
from pyx import canvas, color, deco, path, text, trafo, unit

text.set(text.LatexRunner)
color0 = color.rgb(0.8, 0, 0)
color1 = color.rgb(0, 0, 0.8)
text.preamble(
    r'\usepackage[sfdefault,scaled=.85,lining]{FiraSans}\usepackage{newtxsf}')
text.preamble(r'\usepackage{color}')
text.preamble(r'\definecolor{axis0}{rgb}{%s, %s, %s}' %
              (color0.r, color0.g, color0.b))
text.preamble(r'\definecolor{axis1}{rgb}{%s, %s, %s}' %
              (color1.r, color1.g, color1.b))
unit.set(xscale=1.6, wscale=1.5)

dx = 2
dy = 0.8
c = canvas.canvas()
for nx in range(3):
    for ny in range(3):
        c.text(nx * dx, -ny * dy,
               r'a[\textcolor{axis0}{%s}, \textcolor{axis1}{%s}]' % (ny, nx),
               [text.halign.center])
box = c.bbox()
pd = 0.1
xoff = box.left() - pd
pdx = 0.2
pdy = 0.5
c.stroke(
    path.curve(xoff,
               box.top() + pd, xoff - pdx,
               box.top() - pdy, xoff - pdx,
コード例 #8
0
ファイル: imagearrays.py プロジェクト: gertingold/lit2017
    if ydir:
        p = path.path(path.moveto(*projector(nx, z, ny)),
                      path.lineto(*projector(nx, z, ny+1)),
                      path.lineto(*projector(nx, z+1, ny+1)),
                      path.lineto(*projector(nx, z+1, ny)),
                      path.closepath())
        c.fill(p, [facecolor, color.transparency(trans)])
    x0, y0 = projector(nx, z, ny)
    x1, y1 = projector(nx, z+1, ny)
    c.stroke(path.line(x0, y0, x1, y1), [edgecolor])

projector = graph.graphxyz.central(60, -60, 25).point

unit.set(wscale=1.5, xscale=1.7)
text.set(text.LatexRunner, texenc='utf8')
text.preamble(r'''\usepackage[utf8x]{inputenc}
                  \usepackage{qswiss}''')
c = canvas.canvas()
nxmax = 7
nymax = 5
trans = 0.4

xoff = 5
yoff = 1
edgecolors = (color.rgb(0, 0, 0.8),
              color.rgb(0, 0.6, 0),
              color.rgb(0.8, 0, 0))
w = 0.3
facecolors = (color.rgb(w, w, 1),
              color.rgb(w, 1, w),
              color.rgb(1, w, w))
for nplane, (edgecolor, facecolor) in enumerate(zip(edgecolors, facecolors)):
コード例 #9
0
ファイル: susy.py プロジェクト: alexsparrow/thesis
from pyfeyn.user import *
from pyx.text import preamble
import pyx

preamble(r"\usepackage{hepnicenames}")

def susy_1lepton(fname):
    fd = FeynDiagram()
    p1 = Point(-4, 2)
    p2 = Point(-4, -2)

    int_x = -2
    v1 = Vertex(int_x, 0.3)
    v2 = Vertex(int_x, -0.3)
    ml1 = MultiLine(p1, v1, 3)
    ml2 = MultiLine(p2, v2, 3)
    in_blob = Ellipse(x=int_x, y=0,  xradius=0.5,# fill=[GREY],
                      yradius=1.5, points=[v1,v2]).setFillStyle(HATCHED135)

    int_two_x = 0
    v3 = Vertex(int_two_x, 2)
    v4 = Vertex(int_two_x, -2)

    g1 = Gluino(v1, v3).addLabel(r"\PSgluino")
    g2 = Gluino(v2, v4).addLabel(r"\PSgluino")


    int_three_x = 2
    p_quark1 = Point(int_three_x, 3)
    v_squark1 = Vertex(int_three_x, 1)
コード例 #10
0
    c.stroke(path.curve(xoff, box.top()+pd,
                        xoff-pdx, box.top()-pdy,
                        xoff-pdx, box.bottom()+pdy,
                        xoff, box.bottom()-pd))
    xoff = box.right()+pd
    c.stroke(path.curve(xoff, box.top()+pd,
                        xoff+pdx, box.top()-pdy,
                        xoff+pdx, box.bottom()+pdy,
                        xoff, box.bottom()-pd))
    return c


text.set(text.LatexRunner)
color0 = color.rgb(0.8, 0, 0)
color1 = color.rgb(0, 0, 0.8)
text.preamble(r'\usepackage[sfdefault,scaled=.85,lining]{FiraSans}\usepackage{newtxsf}')
text.preamble(r'\usepackage{color}')
text.preamble(r'\definecolor{axis0}{rgb}{%s, %s, %s}' % (color0.r, color0.g, color0.b))
text.preamble(r'\definecolor{axis1}{rgb}{%s, %s, %s}' % (color1.r, color1.g, color1.b))
unit.set(xscale=1.5, wscale=1.5)

c = canvas.canvas()
m1 = np.arange(4).reshape(2, 2)
c_m1 = matrix_22(m1)
m2 = np.arange(4, 8).reshape(2, 2)
c_m2 = matrix_22(m2)
m3 = np.dot(m1, m2)
c_m3 = matrix_22(m3, dx=0.7)
c.insert(c_m1)
c.insert(c_m2, [trafo.translate(c_m1.bbox().width()+0.1, 0)])
end  = c_m1.bbox().right()+c_m2.bbox().width()+0.1
コード例 #11
0
ファイル: refactoring.py プロジェクト: punkdit/fibonacci
#!/usr/bin/env python

import sys
from math import *
from random import *
import numpy

from pyx import canvas, path, deco, trafo, style, text, color, deformer

text.set(mode="latex") 
text.set(docopt="10pt")
text.preamble(r"\usepackage{amsmath,amsfonts,amssymb}")
text.preamble(r'\usepackage{mathrsfs}')
#text.preamble(r"\def\I{\mathbb{I}}")
text.preamble(r"\def\ket #1{|#1\rangle}")
text.preamble(r"\def\H{\mathscr{H}}")
text.preamble(r"\def\F{\mathscr{H}}")
text.preamble(r"\def\A{\mathcal{A}}")


rgb = color.rgb
rgbfromhexstring = color.rgbfromhexstring

red, green, blue, yellow = (
    rgbfromhexstring("#d00000"),
    rgbfromhexstring("#006000"),
    rgb.blue, rgb(0.75, 0.75, 0)) 

black = rgb(0., 0., 0.) 
blue = rgb(0., 0., 0.8)
lred = rgb(1., 0.4, 0.4)
コード例 #12
0
 def initialize_pyx(self):
     text.set(text.LatexRunner)
     text.preamble(r'\usepackage{arev}\usepackage[T1]{fontenc}')
     unit.set(xscale=2, wscale=7)
コード例 #13
0
ファイル: test_texmessageparser.py プロジェクト: mjg/PyX
 def setUp(self):
     text.set(mode="latex")
     text.preamble(r"\usepackage{graphicx}")
コード例 #14
0
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)

c = canvas.canvas()
framebox(3, 5, ex1color, nw=2)
framebox(4, 0, ex2color, nw=2, nh=2)
framebox(2, 0, ex3color, nh=6)
for nx in (0, 2, 4):
    for ny in (1, 3):
        framebox(nx, ny, ex4color, reducedsize=True)

for nx in range(ncols + 1):
    p = path.path(
        path.moveto(nx * boxsize, 0), path.lineto(nx * boxsize,
                                                  ncols * boxsize),
        path.rlineto(reducedboxsize * cos(angle), reducedboxsize * sin(angle)))
コード例 #15
0
 def setUp(self):
     text.set(mode="latex")
     text.preamble(r"\usepackage{graphicx}")
コード例 #16
0
from pyx import canvas, color, deco, path, style, text, unit


def draw_square(x, y, kante):
    c.fill(path.rect(x, y, kante, kante), [color.grey(1)])
    c.stroke(path.line(x, y, x + kante, y + kante),
             [style.linewidth.thick, color.grey(0.5)])
    c.stroke(path.rect(x, y, kante, kante), [style.linewidth.thick])


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

kante = 1
dist = 0.15
punkte = 1
nrboxes = 3
nrpoints = 3

ldist = 0.05
boxcolor = color.rgb(1, 0.7, 0.4)
c.fill(path.rect(-0.3 * dist, -0.2, 7 * kante + 6.6 * dist, kante + 0.4),
       [boxcolor])
for n in range(nrboxes):
    x = n * (kante + dist)
    draw_square(x, 0, kante)
    c.text(x + ldist * kante, (1 - ldist) * kante, n, [text.valign.top])
    nstr = ""
    if n > 0: nstr = "%+i" % n
コード例 #17
0
def client(clientcolor=color.rgb(0.8, 0.5, 0.5)):
    c = canvas.canvas()
    r = 0.3
    c.fill(path.circle(0, 0, r), [clientcolor])
    r = 0.5
    p = path.path(path.moveto(-r, 0), path.curveto(-r, r, r, r, r, 0),
                  path.closepath())
    c.fill(p, [clientcolor, trafo.translate(0, -1.3 * r)])
    return c


arrowcolor = color.grey(0.5)

text.set(text.LatexRunner)
text.preamble(r'\usepackage{beramono}\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,
コード例 #18
0
import json
import re
import os
import unicodedata
import sys
from pyx import bbox, canvas, color, document, path, svgfile, style, text, trafo, unit

text.set(text.LatexRunner)
text.preamble(r'\usepackage{helvet}')
text.preamble(r'\renewcommand\familydefault{\sfdefault}')

CUT_LINE = True

with open('_data/manifest.json', 'r') as f:
     manifest = json.loads(f.read())
     inventory = manifest['inventory']
     sizes = manifest['sizes']

def slugify(value):
    """
    Normalizes string, converts to lowercase, removes non-alpha characters,
    and converts spaces to hyphens.
    """
    value = re.sub('[^\w\s-]', '', value).strip().lower()
    value = re.sub('[-\s]+', '-', value)
    return value

def get_canvas_size(item):
    canvas_size = None
    for size in sizes:
        w = size["dims"][0] * unit.t_inch
コード例 #19
0
ファイル: render.py プロジェクト: punkdit/morse2019
#from math import sin, cos, pi
from random import seed, random, shuffle
seed(0)  # <----------- seed ------------

from pyx import canvas, path, deco, trafo, style, text, color, deformer
from pyx.color import rgb
from pyx.bbox import bbox
rgbhex = color.rgbfromhexstring

from turtle import Turtle, dopath

#text.set(mode="latex")
text.set(cls=text.LatexRunner)
#text.set(docopt="12pt")
text.preamble(r"\usepackage{amsmath,amsfonts,amssymb}")
#text.preamble(r"\LARGE") #??

north = [text.halign.boxcenter, text.valign.top]
northeast = [text.halign.boxright, text.valign.top]
northwest = [text.halign.boxleft, text.valign.top]
south = [text.halign.boxcenter, text.valign.bottom]
southeast = [text.halign.boxright, text.valign.bottom]
southwest = [text.halign.boxleft, text.valign.bottom]
east = [text.halign.boxright, text.valign.middle]
west = [text.halign.boxleft, text.valign.middle]
center = [text.halign.boxcenter, text.valign.middle]

black = rgb(0., 0., 0.)
blue = rgb(0.1, 0.1, 0.9)
red = lred = rgb(1.0, 0.1, 0.1)
コード例 #20
0
 def setUp(self):
     text.set(engine=text.LatexEngine)
     text.preamble(r"\usepackage{graphicx}")
コード例 #21
0
    c1.stroke(outline, attrs)
    d = deformer.smoothed(0.2)
    c1.stroke(d.deform(foldpath), attrs)
    c1.stroke(path.rect(0.1 * w, 0.3 * h, 0.6 * w, 0.1 * h))
    c1.stroke(path.rect(0.1 * w, 0.45 * h, 0.6 * w, 0.1 * h))
    c1.stroke(path.rect(0.1 * w, 0.6 * h, 0.6 * w, 0.1 * h))
    c1.stroke(path.rect(0.1 * w, 0.75 * h, 0.6 * w, 0.1 * h))
    c1.text(0.1, 0.1, r'\sffamily ' + title, [trafo.scale(0.7)])
    myattrs = [trafo.translate(xoff, yoff), trafo.scale(size)]
    myattrs.extend(attrs)
    c.insert(c1, myattrs)


text.set(text.LatexRunner)
text.preamble(r'''%\usepackage[sfdefault,scaled=0.85,lining]{FiraSans}
                  \usepackage{arev}
                  \usepackage[utf8]{inputenc}''')
unit.set(wscale=1.3)

name = os.path.splitext(sys.argv[0])[0] + '_{}'
for norder in range(4):
    c = canvas.canvas()
    file(c, yoff=2.5, title='JuliaSet', attrs=set_myattrs(norder, 0))
    file(c,
         xoff=1,
         yoff=0,
         title=r'$\sim${}ColorRepresentation',
         attrs=set_myattrs(norder, 1))
    file(c,
         xoff=1,
         yoff=-2.5,
コード例 #22
0
ファイル: trellis.py プロジェクト: punkdit/surface2015
southeast = [text.halign.boxright, text.valign.bottom]
southwest = [text.halign.boxleft, text.valign.bottom]
east = [text.halign.boxright, text.valign.middle]
west = [text.halign.boxleft, text.valign.middle]
center = [text.halign.boxcenter, text.valign.middle]


st_dashed = [style.linestyle.dashed]
st_dotted = [style.linestyle.dotted]

st_Thick = [style.linewidth.Thick]


text.set(mode="latex")
text.set(docopt="10pt")
text.preamble(r"\usepackage{amsmath,amsfonts,amssymb}")
# text.preamble(r"\def\I{\mathbb{I}}")
text.preamble(r"\def\ket #1{|#1\rangle}")
text.preamble(r"\def\bra #1{\langle#1|}")
text.preamble(r"\def\braket #1#2{\langle#1|#2\rangle}")


rgb = color.rgb
rgbfromhexstring = color.rgbfromhexstring

red, green, blue, yellow, orange = (
    rgbfromhexstring("#d00000"),
    rgbfromhexstring("#006000"),
    rgb.blue,
    rgb(0.75, 0.75, 0),
    rgb(0.75, 0.55, 0),
コード例 #23
0
angle = radians(40)
reducedboxsize = 0.65*boxsize

ex1color = color.rgb(0, 0.5, 0)
ex2color = color.rgb(0, 0, 0.7)
ex3color = color.rgb(0.7, 0, 0)

text.set(text.LatexRunner)
preamble = r'''\usepackage[T1]{fontenc}
               \usepackage{bera}
               \renewcommand*\familydefault{\ttdefault}
               \usepackage{color}'''
for nr, elem in enumerate((ex1color, ex2color, ex3color)):
    preamble = preamble+r'\definecolor{{ex{}color}}{{rgb}}{{{}, {}, {}}}'.format(
                  nr+1, elem.r, elem.g, elem.b)
text.preamble(preamble)
unit.set(xscale=1.2)

c = canvas.canvas()
for n in range(5):
    framebox(n+1, ncols-n-1, ex1color)
for nx in (0, 2, 5):
    framebox(nx, 0, ex2color, nh=3, reducedsize=True)
for n in (0, 2, 5):
    framebox(2, (ncols-n-1), ex3color)

for nx in range(ncols+1):
    p = path.path(path.moveto(nx*boxsize, 0),
                  path.lineto(nx*boxsize, ncols*boxsize),
                  path.rlineto(reducedboxsize*cos(angle), reducedboxsize*sin(angle)))
    c.stroke(p)
コード例 #24
0
ファイル: braid.py プロジェクト: punkdit/thesis2015
southeast = [text.halign.boxright, text.valign.bottom]
southwest = [text.halign.boxleft, text.valign.bottom]
east = [text.halign.boxright, text.valign.middle]
west = [text.halign.boxleft, text.valign.middle]
center = [text.halign.boxcenter, text.valign.middle]


st_dashed = [style.linestyle.dashed]
st_dotted = [style.linestyle.dotted]

st_Thick = [style.linewidth.Thick]


text.set(mode="latex")
text.set(docopt="10pt")
text.preamble(r'\usepackage{amsmath,amsfonts,amssymb}')
#text.preamble(r"\def\I{\mathbb{I}}")
text.preamble(r"\def\ket #1{|#1\rangle}")


rgb = color.rgb
rgbfromhexstring = color.rgbfromhexstring

red, green, blue, yellow, orange = (
    rgbfromhexstring("#d00000"),
    rgbfromhexstring("#006000"),
    rgb.blue, 
    rgb(0.75, 0.75, 0),
    rgb(0.75, 0.55, 0),
    )
コード例 #25
0
ファイル: fresnel.py プロジェクト: gertingold/feynman-intro
from math import sqrt
from pyx import canvas, color, deco, path, style, text, unit

axislen = 3

text.set(engine=text.LatexEngine)
text.preamble(r'''\usepackage[sfdefault,scaled=.85]{FiraSans}
                  \usepackage{newtxsf}
                  \usepackage{nicefrac}''')
unit.set(vscale=1.2, wscale=1.3, xscale=1.3)
c = canvas.canvas()
c.stroke(path.line(-0.2*axislen, 0, axislen, 0), [deco.earrow])
c.text(axislen+0.1, 0, 'Re($x$)', [text.valign.middle])
c.stroke(path.line(0, -0.2*axislen, 0, axislen), [deco.earrow])
c.text(0.2, axislen, 'Im($x$)', [text.valign.top])
r = 0.85*axislen
p = path.path(path.moveto(0, 0),
              path.lineto(r, 0),
              path.arc(0, 0, r, 0, 45),
              path.lineto(0, 0),
              path.closepath())
pathcolor = color.rgb(0.2, 0, 0.8)
c.stroke(p, [style.linewidth.thick, style.linejoin.round, pathcolor])
c.stroke(path.line(0, 0, 0.53*axislen, 0), [deco.earrow, pathcolor])
c.stroke(path.path(path.arc(0, 0, r, 0, 23)), [deco.earrow, pathcolor])
c.stroke(path.path(path.moveto(r/sqrt(2), r/sqrt(2)),
                   path.lineto(0.48*r/sqrt(2), 0.48*r/sqrt(2))),
         [deco.earrow, pathcolor])
c.text(0.33, 0.11, r'\footnotesize$\nicefrac{\pi}{4}$', [pathcolor])
c.stroke(path.path(path.arc(0, 0, 0.82, 0, 45)),
         [style.linewidth.thin, pathcolor])
コード例 #26
0
ファイル: sunburst.py プロジェクト: mikemwang/sunburst
"""python file to create a sunburst diagram using most used words in English,
each layer represents the letter at that index in the word"""

from math import sin, cos, pi  #'
from pyx import path, style, color, text, trafo  #'
from .colormap import color_map
from .code_parser import parse_source, parse_trace

text.set(text.LatexRunner)  #'
text.preamble(r"\usepackage{cmtt}")  #'


def generate_diagrams(data, shape_canvas, text_canvas, settings, source_path):
    diagrams = {}
    # draw bounding box so the file is the right size and shape
    x = settings['output']['x']
    y = settings['output']['y']

    # draw the bounding box
    shape_canvas.stroke(
        path.rect(-0.25 * x, -0.5 * y, x, y),
        [color.rgb.white, style.linewidth(0.001)])
    for entry in data:
        name = entry[0]
        origin = entry[1]
        data_source = entry[2]
        diagrams[name] = Sunburst(shape_canvas, text_canvas, settings,
                                  source_path, name, origin, data_source)
        diagrams[name].draw()
        stop_trace()
    return diagrams
コード例 #27
0
 def initialize_pyx(self):
     text.set(text.LatexRunner)
     text.preamble(
         r'\usepackage[sfdefault,scaled=.85,lining]{FiraSans}\usepackage{newtxsf}'
     )
     unit.set(xscale=2.5, wscale=7)
コード例 #28
0
                     boxsize-2*linewidth, boxsize-2*linewidth).reversed()
         )
    c.fill(p, [boxcolor])


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

text.set(text.LatexRunner)
text.preamble(r'''\usepackage[T1]{fontenc}
                  \usepackage{bera}
                  \renewcommand*\familydefault{\ttdefault}
                  \usepackage{color}
                  \definecolor{ex1}{rgb}{0, 0, 0.7}
                  \definecolor{ex2}{rgb}{0, 0.6, 0}
                  \definecolor{ex3}{rgb}{0.7, 0, 0}''')
unit.set(xscale=1.2)

c = canvas.canvas()

ex1color = color.rgb(0, 0, 0.7)
linewidth = 0.1*boxsize
for n in (0, 2, 5):
    c.fill(path.rect(n*boxsize+linewidth, linewidth,
                     boxsize-2*linewidth, 3*boxsize-2*linewidth),
           [ex1color])
    c.fill(path.rect(n*boxsize+2*linewidth, 2*linewidth,
                     boxsize-4*linewidth, 3*boxsize-4*linewidth),
コード例 #29
0
ファイル: testdata.py プロジェクト: dkiela/thesis
print "xcorr = ", xcorr
print "xcorr.argmax = ", xcorr.argmax()
print "xcorr.len = ", len(xcorr)
print len(t)
print "Recovered time shift = ", recovered_time_shift
print "Recovered phase shift: %.2f pi" % (recovered_phase_shift/pi)

pyplot.plot(t, )
pyplot.show()
quit()

from pyx import canvas, graph, text, color, style, trafo, unit
from pyx.graph import axis, key

text.set(mode="latex")
text.preamble(r"\usepackage{txfonts}")
figwidth = 12
gkey = key.key(pos=None, hpos=0.05, vpos=0.8)
xaxis = axis.linear(title=r"Time, \(t\)")
yaxis = axis.linear(title="Signal", min=-5, max=17)
g = graph.graphxy(width=figwidth, x=xaxis, y=yaxis, key=gkey)
plotdata = [graph.data.values(x=t, y=signal+offset, title=label) for label, signal, offset in (r"\(A(t) = \mathrm{square}(2\pi t/T)\)", A, 2.5), (r"\(B(t) = \mathrm{sawtooth}(\phi + 2 \pi t/T)\)", B, -2.5)]
linestyles = [style.linestyle.solid, style.linejoin.round, style.linewidth.Thick, color.gradient.Rainbow, color.transparency(0.5)]
plotstyles = [graph.style.line(linestyles)]
g.plot(plotdata, plotstyles)
g.plot(graph.data.values(x=t, y=listX, title="Blah"), plotstyles)
g.text(10*unit.x_pt, 0.56*figwidth, r"\textbf{Cross correlation of noisy anharmonic signals}")
g.text(10*unit.x_pt, 0.33*figwidth, "Phase shift: input \(\phi = %.2f \,\pi\), recovered \(\phi = %.2f \,\pi\)" % (phase_shift/pi, recovered_phase_shift/pi))
xxaxis = axis.linear(title=r"Time Lag, \(\Delta t\)", min=-1.5, max=1.5)
yyaxis = axis.linear(title=r"\(A(t) \star B(t)\)")
gg = graph.graphxy(width=0.2*figwidth, x=xxaxis, y=yyaxis)
コード例 #30
0
    primelist = [nr for nr, isprime in enumerate(candidates) if isprime]
    return primelist


def is_time(n):
    hours, minutes = divmod(n, 100)
    return 0 <= hours <= 23 and 0 <= minutes <= 59


def formattime(t):
    s = f'{t:04}'
    return fr'\scriptsize\texttt{{{s[0:2]}:{s[2:]}}}'


text.set(text.LatexRunner)
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)])

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
コード例 #31
0
import numpy
import scipy.sparse.linalg as la

from qupy.condmat.models import build_model
from qupy.smap import SMap
from qupy.argv import argv

try:
    from pyx import canvas, path, deco, trafo, style, text, color, deformer
    from pyx.color import rgb

    if 0:
        text.set(mode="latex")
        text.set(docopt="12pt")
        text.preamble(r"\usepackage{amsmath,amsfonts,amssymb}")

        text.preamble(r"\def\ket #1{|#1\rangle}")

    black = rgb(0., 0., 0.)
    blue = rgb(0., 0., 0.8)
    lred = rgb(1., 0.4, 0.4)
    white = rgb(1., 1., 1.)
    grey = rgb(0.75, 0.75, 0.75)
    shade = grey
    shade0 = rgb(0.75, 0.75, 0.75)
    shade1 = rgb(0.80, 0.80, 0.80)
    shade2 = rgb(0.85, 0.85, 0.85)

    light_shade = rgb(0.85, 0.65, 0.1)
    light_shade = rgb(0.9, 0.75, 0.4)
コード例 #32
0
            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])


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

for stride in (0, 2, 3):
    c = canvas.canvas()
    make_stride_figure(c, stride)
    c.writePDFfile('_'.join([os.path.splitext(sys.argv[0])[0], str(stride)]))
コード例 #33
0
ファイル: poster.py プロジェクト: punkdit/fibonacci

rgb = color.rgb
rgbfromhexstring = color.rgbfromhexstring

red, green, blue, yellow = (rgb.red,
    rgbfromhexstring("#008000"),
    rgb.blue, rgb(0.75, 0.75, 0))

blue = rgb(0., 0., 0.8)
lred = rgb(1., 0.4, 0.4)


text.set(mode="latex") 
#text.set(docopt="10pt")
text.preamble(r'\usepackage{amsfonts}')
text.preamble(r"\def\I{\mathbb{I}}")


c = canvas.canvas()
# [trafo.scale(10.)])

# Dimensions of A0 in cm
SCALE = 4.
#w = 118.9 / SCALE
#h = 84.1 / SCALE

# portrait
w = 84.1 / SCALE
h = 118.9 / SCALE
コード例 #34
0
 def initialize_pyx(self):
     text.set(text.LatexRunner)
     text.preamble(r'\usepackage[sfdefault,scaled=.85,lining]{FiraSans}\usepackage{newtxsf}')
     unit.set(xscale=2.5, wscale=7)