|
From: Frederico C W. <fr...@gm...> - 2020-03-25 23:22:26
|
Howdy,
I'm trying PyX for the first time, and looking to adapt examples to my
need,
but after some effort, couldn't get the text to appear on the canvas.
Thought it would write the text somewhere near the drawn vectors. .. but
it hasn't text anywhere.
Would appreciate some help here.
Thanks in advance.,
Frederico C Wilhelms
By the way., Debian , 64 bits , Python Python 3.7.3
, Pyx 0.15 ., installed by pip3 .,
*******
mpy as np
import math
from pyx import *
def vector(x1, y1, x2, y2, t, pos=0.5, distance=0.1):
c = canvas.canvas()
sz=1
tg_s = (y2-y1) / (x2-x1)
theta = math.atan(tg_s)
dx = sz * math.cos( theta )
dy = sz * math.sin( theta )
#
c.stroke(path.line(x1, y1, x2-dx, y2-dy),
[style.linewidth(sz), color.rgb.black,
deco.earrow([deco.stroked([color.rgb.black])], size=sz)] )
c.text_pt( x2+10, y2+10, t, [text.halign.boxcenter] )
# c.insert(textbox)
return c
rect1 = path.path(path.moveto(0, 0), path.lineto(1, 0),
path.moveto(1, 0), path.lineto(1, 1),
path.moveto(1, 1), path.lineto(0, 1),
path.moveto(0, 1), path.lineto(0, 0))
rect2 = path.path(path.moveto(2, 0), path.lineto(3, 0),
path.lineto(3, 1), path.lineto(2, 1),
path.lineto(2, 0))
rect3 = path.path(path.moveto(4, 0), path.lineto(5, 0),
path.lineto(5, 1), path.lineto(4, 1) )
# path.closepath())
pt=path.path()
c = canvas.canvas()
nlin = 30
mult = 10
lmax = nlin * mult
for ls in range( nlin ) :
# pt = path.path( path.moveto(1,ls) , path.lineto(255,ls) ,
path.closepath() )
pt = path.path(path.moveto(0, ls*mult), path.lineto(lmax,ls*mult),
path.moveto(ls*mult, 0), path.lineto(ls*mult,lmax) )
c.stroke( pt , [style.linewidth.Thin] )
c.text( ls*mult , 0 , str( ls ) )
#for ls in range( nlin ) :
# c.text( ls*mult , 0 , ls , [text.halign.boxcenter ])
for I in range( 1 , 7 ) :
c.insert( vector( 3 * mult , 1 * mult , 5 * mult , I * mult ,
repr( "$\vec{v}$=(5, " + str(I) + ")" ) ) )
#vt0 = path.path( path.moveto( vtorigx * mult , vtorigy * mult ) ,
# path.lineto( (vtx + vtorigx) * mult , (vty
+ vtorigy)*mult ) )
#c.stroke( vt0 , [ style.linewidth.THICK , deco.earrow.normal ] )
#c.stroke( pt , [style.linewidth.THICK] )
#c.stroke(rect1, [style.linewidth.THICK])
#c.stroke(rect2, [style.linewidth.THICK])
#c.stroke(rect3, [style.linewidth.THICK])
#c.writeEPSfile("pathitem")
#c.writePDFfile("pathitem")
c.writePDFfile("pathitem")
quit()
|