コード例 #1
0
    def scale(self, val=0):
        """Interface to the global pyx scale: unit.set(uscale=val)
        Either sets scale directly or uses the instance variable default.
        0.25 scales to 25%, 3.0 scales to 300%.
        -  http://pyx.sourceforge.net/manual/unit.html
        -  http://nullege.com/codes/search/pyx.unit.set
        -  https://github.com/mjg/PyX/blob/master/test/unit/test_unit.py
        """

        if val == 0:
            val = self.uscale
        unit.set(uscale=val, defaultunit="inch")
コード例 #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
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
コード例 #4
0
    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

random.seed(812357)

arrowcolor = color.grey(0.5)

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))]
for x, y in pos:
    c.insert(server(0.3), [trafo.translate(1.5*x, 1.5*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])
pos.append(pos[0])
fak = 0.3
for (x1, y1), (x2,y2) in zip(pos[:-1], pos[1:]):
    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])
コード例 #5
0
#!/usr/bin/env python

import pygame
from pygame.locals import *
import time
from pyx import path, unit, deformer
import copy
import math
import pickle

# for pyx (Trajectory.arclen)
# ALL UNITS m (distance), m/s (velocity), and s (time)
unit.set(defaultunit="m")
metersPerPoint = 0.00035277
""" METHODS"""
''' makeTrajectory:
    Show the user a view & make a trajectory from input
'''


def makeTrajectory(loadfile=None, savefile=None):
    if loadfile:
        with open('trajectories/' + loadfile + '.p', 'rb') as handle:
            traj = pickle.load(handle)
            traj.makePath()  # remake path object...can't pickle

    else:
        pygame.init()
        """__________Initiates Class Objects and Umbrella Variables___________"""

        #Creates display surface
コード例 #6
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)
コード例 #7
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)
コード例 #8
0
ファイル: __init__.py プロジェクト: Jasonh90/Invaders
"""
PyX backend to the Tk Turtle

This is an attempt to speed up grading of the TkTurtle assignment. It replaces the Tcl/Tk 
backend with PyX, which creates a PDF of the output.

Author: Walker M. White (wmw2)
Date:   July 13, 2017 (Python 3 version)
"""
from pyx import unit
from pyx import text

unit.set(defaultunit='pt')
text.set(cls=text.LatexRunner)

from .pdfview import PDFView
from .window import Window
from .turtle import Turtle
from .pen import Pen
コード例 #9
0
ファイル: ieee754_64.py プロジェクト: gertingold/eidprog
from pyx import canvas, path, style, text, unit

text.set(text.LatexRunner)
unit.set(xscale=0.8)

b = 0.8

c = canvas.canvas()
offset = 0
c.stroke(path.rect(offset, 0, b, b))
c.stroke(path.path(path.moveto(offset+0.1*b, -0.1),
                   path.lineto(offset+0.1*b, -1.2),
                   path.lineto(offset+0.3*b, -1.2)), [style.linewidth.thin])
c.text(offset+0.2*b, -1.1, r"\sffamily Vorzeichen")
c.text(0.5*b, 1.1*b, r"\sffamily 1 Bit", [text.halign.center])
c.text(0.5*b, 0.5*b, r"\sffamily S", [text.halign.center, text.valign.middle])
offset = 1.2*b
c.stroke(path.path(path.moveto(offset+0.5*b, b),
                   path.lineto(offset, b),
                   path.lineto(offset, 0),
                   path.lineto(offset+0.5*b, 0)))
c.stroke(path.path(path.moveto(offset+0.1*b, -0.1),
                   path.lineto(offset+0.1*b, -0.7),
                   path.lineto(offset+0.3*b, -0.7)), [style.linewidth.thin])
c.text(offset+0.2*b, -0.6, r"\sffamily Exponent")
offset = offset+0.5*b
c.stroke(path.line(offset, 0, offset+b, 0), [style.linestyle.dotted])
c.stroke(path.line(offset, b, offset+b, b), [style.linestyle.dotted])
c.text(offset+0.5*b, 1.1*b, r"\sffamily 11 Bits", [text.halign.center])
c.text(offset+0.5*b, 0.5*b, r"\sffamily E",
       [text.halign.center, text.valign.middle])
コード例 #10
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()
コード例 #11
0
ファイル: imagearrays.py プロジェクト: gertingold/lit2017
                      path.closepath())
        c.fill(p, [facecolor, color.transparency(trans)])
    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),
コード例 #12
0
    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,
         title=r'$\sim${}Grid',
         attrs=set_myattrs(norder, 2))
コード例 #13
0
                      path.closepath())
        c.fill(p, [facecolor, color.transparency(trans)])
    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, -50, 25).point

unit.set(wscale=1.5)
c = canvas.canvas()
nxmax = 7
nymax = 5
trans = 0.4
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)):
    zoff = 1.04*(2-nplane)
    frontplane(zoff+1, nxmax, nymax, facecolor, edgecolor, trans)
    for nx in range(nxmax, -1, -1):
コード例 #14
0
 def initialize_pyx(self):
     text.set(text.LatexRunner)
     text.preamble(r'\usepackage{arev}\usepackage[T1]{fontenc}')
     unit.set(xscale=2, wscale=7)
コード例 #15
0
from pyx import bitmap, canvas, color, deco, path, text, unit

axiscolor = color.rgb(0.7, 0, 0)
i = bitmap.jpegimage("phyphox_measurement.jpg")
unit.set(vscale=10, wscale=10, xscale=10)
c = canvas.canvas()
c.insert(bitmap.bitmap(0, 0, i, compressmode=None))
c.stroke(path.line(40, 26, 40, 45), [axiscolor, deco.earrow])
c.text(41, 45, '$z$', [text.valign.top, axiscolor])
c.stroke(path.line(40, 26, 46, 10), [axiscolor, deco.earrow])
c.text(46.8, 10.5, '$x$', [axiscolor])
c.stroke(path.line(40, 26, 66, 32), [axiscolor, deco.earrow])
c.text(66, 33.5, '$y$', [text.halign.right, axiscolor])
c.writePDFfile()
コード例 #16
0
    processids = sorted(set([r[2] for r in results]))
    processdict = dict(zip(processids, range(len(processids))))
    return (len(processdict), start, ende,
            [(processdict[r[2]], r[3]-start, r[4]-start) for r in results])

npts = 1024
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)
コード例 #17
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()
コード例 #18
0
        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])

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)]))
コード例 #19
0
                   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)
c.insert(c_m2, [trafo.translate(c_m1.bbox().width() + 0.1, 0)])
end = c_m1.bbox().right() + c_m2.bbox().width() + 0.1
dist2 = 0.6
c.insert(c_m3, [trafo.translate(end + dist2 - c_m3.bbox().left(), 0)])
ycenter = 0.5 * (c_m1.bbox().top() + c_m1.bbox().bottom())
for dy in (-0.05, 0.05):
コード例 #20
0

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
nx = int(w / unit.tocm(textwidth))
コード例 #21
0
           'pentadecathlon': [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                              [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
                              [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
                              [0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0],
                              [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
                              [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
                              [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
                              [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
                              [0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0],
                              [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
                              [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
                              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
          }

text.set(text.LatexRunner)
unit.set(xscale=4, wscale=2)
c = canvas.canvas()
xpos = 0
for k in ('blinker', 'beacon', 'toad', 'glider',
          'pentadecathlon', 'pulsar'):
    c.insert(draw_config(k), [trafo.translate(xpos, 0)])
    wd = len(configs[k][0])
    c.text(xpos+0.5*wd,
           -0.5, r'\sffamily {}'.format(k),
           [text.halign.center, text.valign.top])
    xpos = xpos+wd+1
filename = os.path.splitext(sys.argv[0])[0]+'.png'
c.writeGSfile(filename, resolution=200)
コード例 #22
0
from math import atan, degrees
from pyx import canvas, color, path, style, text, unit

unit.set(xscale=0.8)
c = canvas.canvas()
c.fill(path.circle(0, 0, 0.1), [color.grey(0.5)])
c.fill(path.circle(2, 1, 0.1), [color.grey(0.5)])
c.stroke(path.line(0, 0, -1., -0.2),
         [style.linewidth.Thick, style.linestyle.dotted])
c.stroke(path.line(2, 1, 2.7, 1.7),
         [style.linewidth.Thick, style.linestyle.dotted])
c.stroke(path.line(0, 0, 2, 1), [style.linewidth.thick])
c.stroke(path.path(path.moveto(0, 0), path.lineto(2, 0), path.lineto(2, 1)))
c.text(0.5, 0.1, r'$\varphi$')
c.stroke(path.path(path.arc(0, 0, 0.8, 0, degrees(atan(0.5)))))
c.text(1, 0.6, r'$\ell=1$', [text.halign.right])
c.text(1, -0.1, r'$\cos(\varphi)$', [text.halign.center, text.valign.top])
c.text(2.1, 0.5, r'$\sin(\varphi)$', [text.valign.middle])
c.writeGSfile(device='pnggray', resolution=200)
コード例 #23
0
from math import pi
from pyx import canvas, color, deco, graph, path, style, text, unit

trange = 8
linecolor = color.rgb(0.2, 0, 0.8)

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

painter_x = graph.axis.painter.regular(basepathattrs=[deco.earrow],
                                       titlepos=1,
                                       titledist=-0.4,
                                       titleattrs=[text.halign.right])

painter_y = graph.axis.painter.regular(basepathattrs=[deco.earrow],
                                       titlepos=1.03,
                                       titledist=0.15,
                                       titleattrs=[text.valign.top],
                                       titledirection=None)

g = graph.graphxy(width=5,
                  height=2,
                  xaxisat=0,
                  yaxisat=0,
                  x=graph.axis.linear(title="$t$",
                                      min=0,
                                      max=trange,
                                      painter=painter_x,
コード例 #24
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,
コード例 #25
0
                       [text.halign.boxcenter, text.valign.middle]))
        elif i % 450 == 0:
            ca.insert(
                t.text(x3, y3, "\\scriptsize " + str(i // 10),
                       [text.halign.boxcenter, text.valign.middle]))
        elif i % 50 == 0:
            ca.insert(
                t.text(x3, y3, "\\tiny " + str(i // 10),
                       [text.halign.boxcenter, text.valign.middle]))


ca = canvas.canvas()

#scale to just fit inside radius 11 circle
basescale = (insize) / (sqrt(n) + 1)
unit.set(defaultunit="inch")

#init variables
pi2 = 2 * pi
ctr = 0
pages = 0

for j in range(n):
    i = j + 2
    ctr += 1

    # compute co-ordinates
    r = sqrt(i)
    theta = r * pi2
    x = cos(theta) * r * basescale
    y = sin(theta) * r * basescale
コード例 #26
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])
コード例 #27
0
ファイル: make_icons.py プロジェクト: mitcho/clld
"""
script to create the default set of map marker icons distributed with clld.
"""
import sys

try:
    import pyx
    from pyx import bbox, unit, style, path, color, canvas, deco
    # set the scale to 1/20th of an inch
    unit.set(uscale=0.05, wscale=0.02, defaultunit="inch")

    #linewidth = style.linewidth(1.2)
    linewidth = style.linewidth(1.1)
except ImportError:  # pragma: no cover
    pyx = False

from pyramid.path import AssetResolver

from clld.web.icon import ICONS


def polygon(*points):  # pragma: no cover
    args = []
    for i, point in enumerate(points):
        args.append(path.moveto(*point) if i == 0 else path.lineto(*point))
    args.append(path.closepath())
    return path.path(*args)


shapes = {
    "c": path.circle(20, 20, 13.6),  # circle
コード例 #28
0
if not opts.show_domain:
  # Compute f(z) over grid
  W = zeros(shape=(M, N), dtype=complex)
  for v in xrange(0, N):
    Z = R * exp(1j*Theta[v])
    for u in xrange(0, M):
      W[u,v] = gauss_quad32(schwarz_christoffel_integrand, 
                          (a, b, Z[u], Z[u+1]-Z[u]))
  W = cumsum(W, axis=0)
else:
  # Domain contours are just concentric circles
  W = 36.0 * R[1:].reshape(-1,1) * exp(1j*Theta).reshape(1,-1)

# Start vector drawing with PyX
unit.set(uscale=0.075)
cvs = canvas.canvas()

if opts.show_wavefronts:
  if opts.curved_contours:
    for u in xrange(0, M-1):
      cvs.stroke(interpolated_path(W[u,:], shape=opts.shape))
    cvs.stroke(polygonal_path(W[M-1,:]))
  else:
    for u in xrange(0, M):
      cvs.stroke(polygonal_path(W[u,:]))

if opts.show_rays:
  if opts.curved_contours:
    for v in xrange(0, N):
      U = [ 0j ] + [ w for w in W[:,v] ]
コード例 #29
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()
コード例 #30
0
ファイル: make_icons.py プロジェクト: clld/cobl2
"""script to create the default set of map marker icons distributed with clld."""
import os
import sys

from csvw.dsv import reader
import pyx
from pyx import bbox, unit, style, path, color, canvas, deco
# set the scale to 1/20th of an inch
unit.set(uscale=0.05, wscale=0.02, defaultunit="inch")

linewidth = style.linewidth(1.2)


def pyxColor(string):
    """Return a pyxColor instance.

    :param string: RGB color name like 'ffffff'
    :return: pyx color.

    >>> assert pyxColor('ffffff')
    """
    assert len(string) == 6
    colorTuple = tuple(
        int('0x' + c, 16) for c in [string[i:i + 2] for i in range(0, 6, 2)])
    return color.rgb(*[i / 255.0 for i in colorTuple])


if __name__ == '__main__':  # pragma: no cover
    out = sys.argv[1]
    if not pyx:
        sys.exit(1)
コード例 #31
0
ファイル: listnumbering2.py プロジェクト: gertingold/eidprog
from pyx import canvas, path, style, text, unit


def draw_square(x, y, kante):
    c.stroke(path.rect(x, y, kante, kante), [style.linewidth.thick])

text.set(text.LatexRunner)
unit.set(xscale=1.3)
c = canvas.canvas()

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

for n in range(nrboxes):
    x = n*(kante+dist)
    draw_square(x, 0, kante)
    c.text(x+0.5*kante, kante+0.2, r"\texttt{%s}" % n, [text.halign.center])
    nstr = ""
    if n > 0:
        nstr = "%+i" % n
    c.text(x+0.5*kante, -0.2, r"\texttt{-N%s}" % nstr,
           [text.halign.center, text.valign.top])
    x = (n+nrboxes)*(kante+dist)+dist+punkte
    draw_square(x, 0, kante)
    c.text(x+0.5*kante, kante+0.2, r"\texttt{N%s}" % (n-3),
           [text.halign.center])
    c.text(x+0.5*kante, -0.2, r"\texttt{%s}" % (n-3),
           [text.halign.center, text.valign.top])
コード例 #32
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():
コード例 #33
0
                      path.lineto(*projector(nx, z + 1, ny)), path.closepath())
        c.fill(p, [facecolor, color.transparency(trans)])
    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, -50, 25).point

unit.set(wscale=1.5)
c = canvas.canvas()
nxmax = 7
nymax = 5
trans = 0.4
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)):
    zoff = 1.04 * (2 - nplane)
    frontplane(zoff + 1, nxmax, nymax, facecolor, edgecolor, trans)
    for nx in range(nxmax, -1, -1):
        for ny in range(nymax + 1):
            corner(nx, ny, zoff, facecolor, edgecolor, trans, nx != 0,
                   ny != nymax)
    frontplane(zoff, nxmax, nymax, facecolor, edgecolor, trans)
コード例 #34
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
コード例 #35
0
import os
import sys

import numpy as np
from pyx import canvas, color, path, text, unit

def draw_grid():
    c.stroke(path.rect(0, 0, 25, 2))
    for n in range(24):
        c.stroke(path.line(n+1, 0, n+1, 2))
    c.stroke(path.line(0, 1, 25, 1))

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

c = canvas.canvas()
c.fill(path.rect(0, 1, 2, 1), [color.grey(0.7)])
c.text(0.5, 1.5, '0', [text.halign.center, text.valign.middle])
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: