Skip to content

Commit 6bc7247

Browse files
author
p12
committed
images: Add scripts for generating plots of ceil(), floor(), trunc() and round()
1 parent 3c54e88 commit 6bc7247

File tree

4 files changed

+162
-1
lines changed

4 files changed

+162
-1
lines changed

images/fix_svg-math.xsl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsl:stylesheet version="1.0"
3+
xmlns="http://www.w3.org/2000/svg"
4+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5+
xmlns:str="http://exslt.org/strings"
6+
xmlns:svg="http://www.w3.org/2000/svg"
7+
>
8+
<xsl:output indent="yes"
9+
method="xml"
10+
encoding="UTF-8"
11+
standalone="no"
12+
doctype-public="-//W3C//DTD SVG 1.1//EN"
13+
doctype-system="http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"/>
14+
15+
<xsl:template match="node()|@*">
16+
<xsl:copy>
17+
<xsl:apply-templates select="node()|@*"/>
18+
</xsl:copy>
19+
</xsl:template>
20+
21+
<xsl:template match="/svg:svg/@width">
22+
<xsl:attribute name="width">
23+
<xsl:value-of select="str:replace(.,'pt','px')"/>
24+
</xsl:attribute>
25+
</xsl:template>
26+
27+
<xsl:template match="/svg:svg/@height">
28+
<xsl:attribute name="height">
29+
<xsl:value-of select="str:replace(.,'pt','px')"/>
30+
</xsl:attribute>
31+
</xsl:template>
32+
33+
</xsl:stylesheet>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ do
88
tmpfile="output/$i.tmp"
99
dot -Tsvg -o$tmpfile $infile
1010
dot -Timap $infile | sed 1d | awk '{sub(/,/, " ", $3); sub(/,/, " ", $4); print $1" "$3" "$4" [["$2"]]"; };' > $mapfile
11-
xsltproc --novalid fix_svg.xsl $tmpfile > $outfile
11+
xsltproc --novalid fix_svg-dot.xsl $tmpfile > $outfile
1212
rm $tmpfile
1313
done
14+
15+
python math-rounding.py

images/math-rounding.py

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/usr/bin/python
2+
3+
import pylab
4+
import os
5+
6+
DATA = (
7+
( 'floor',
8+
( (-3, -3, 'T'),
9+
(-2, -3, 'F'),
10+
(-2, -2, 'T'),
11+
(-1, -2, 'F'),
12+
(-1, -1, 'T'),
13+
( 0, -1, 'F'),
14+
( 0, 0, 'T'),
15+
( 1, 0, 'F'),
16+
( 1, 1, 'T'),
17+
( 2, 1, 'F'),
18+
( 2, 2, 'T'),
19+
( 3, 2, 'F'),
20+
( 3, 3, 'T'),
21+
( 4, 3, 'F')
22+
)
23+
),
24+
( 'ceil',
25+
( (-4, -3, 'F'),
26+
(-3, -3, 'T'),
27+
(-3, -2, 'F'),
28+
(-2, -2, 'T'),
29+
(-2, -1, 'F'),
30+
(-1, -1, 'T'),
31+
(-1, 0, 'F'),
32+
( 0, 0, 'T'),
33+
( 0, 1, 'F'),
34+
( 1, 1, 'T'),
35+
( 1, 2, 'F'),
36+
( 2, 2, 'T'),
37+
( 2, 3, 'F'),
38+
( 3, 3, 'T')
39+
)
40+
),
41+
( 'trunc',
42+
( (-4, -3, 'F'),
43+
(-3, -3, 'T'),
44+
(-3, -2, 'F'),
45+
(-2, -2, 'T'),
46+
(-2, -1, 'F'),
47+
(-1, -1, 'T'),
48+
(-1, 0, 'F'),
49+
( 1, 0, 'F'),
50+
( 1, 1, 'T'),
51+
( 2, 1, 'F'),
52+
( 2, 2, 'T'),
53+
( 3, 2, 'F'),
54+
( 3, 3, 'T'),
55+
( 4, 3, 'F')
56+
)
57+
),
58+
( 'round_away_zero',
59+
( (-3.5, -3, 'F'),
60+
(-2.5, -3, 'T'),
61+
(-2.5, -2, 'F'),
62+
(-1.5, -2, 'T'),
63+
(-1.5, -1, 'F'),
64+
(-0.5, -1, 'T'),
65+
(-0.5, 0, 'F'),
66+
( 0.5, 0, 'F'),
67+
( 0.5, 1, 'T'),
68+
( 1.5, 1, 'F'),
69+
( 1.5, 2, 'T'),
70+
( 2.5, 2, 'F'),
71+
( 2.5, 3, 'T'),
72+
( 3.5, 3, 'F'),
73+
( 3.5, 4, 'T')
74+
)
75+
)
76+
)
77+
78+
font = {'family' : 'DejaVu Serif',
79+
'weight' : 'normal',
80+
'size' : 9}
81+
82+
pylab.rc('font', **font)
83+
84+
for i in xrange(len(DATA)):
85+
(name,idata) = DATA[i]
86+
87+
fig = pylab.figure(figsize=(200.0/72.0,200.0/72.0))
88+
ax = fig.add_subplot(111)
89+
90+
for j in xrange(len(idata)/2):
91+
(x1,y1,fill) = idata[j*2]
92+
(x2,y2,fill) = idata[j*2+1]
93+
x = (x1, x2)
94+
y = (y1, y2)
95+
l = ax.plot(x, y)
96+
pylab.setp(l, 'color', '#0000FF')
97+
pylab.setp(l, 'linewidth', 0.5)
98+
99+
for j in xrange(len(idata)):
100+
(x,y,fill) = idata[j]
101+
102+
l = ax.plot(x, y, marker='o')
103+
104+
pylab.setp(l, 'markersize', 7.5)
105+
pylab.setp(l, 'markeredgewidth', 0.5)
106+
pylab.setp(l, 'markeredgecolor', '#0000FF')
107+
if fill == 'T':
108+
pylab.setp(l, 'markerfacecolor', '#0000FF')
109+
else:
110+
pylab.setp(l, 'markerfacecolor', 'white')
111+
112+
ax.grid(True)
113+
ax.set_axisbelow(True)
114+
ax.tick_params(pad = 7.5)
115+
ax.set_aspect(1.0)
116+
ax.set_xlim((-3.5, 3.5))
117+
ax.set_ylim((-3.5, 3.5))
118+
119+
outfile = 'output/math-' + name + '.svg'
120+
tmpfile = outfile + '.tmp'
121+
pylab.savefig(tmpfile, format='svg')
122+
os.system('xsltproc --novalid fix_svg-math.xsl ' + tmpfile + ' > ' + outfile)
123+
os.system('rm ' + tmpfile)
124+
125+
pylab.close()
126+

0 commit comments

Comments
 (0)