Skip to content

Instantly share code, notes, and snippets.

@richfitz
Last active January 17, 2016 19:22
Show Gist options
  • Save richfitz/a8b8840a2f932993123c to your computer and use it in GitHub Desktop.
Save richfitz/a8b8840a2f932993123c to your computer and use it in GitHub Desktop.
%!PS-Adobe-3.0 EPSF-3.0
%%Creator: cairo 1.10.2 (http://cairographics.org)
%%CreationDate: Fri Apr 18 22:50:20 2014
%%Pages: 1
%%BoundingBox: 0 -1 482 191
%%DocumentData: Clean7Bit
%%LanguageLevel: 2
%%EndComments
%%BeginProlog
/cairo_eps_state save def
/dict_count countdictstack def
/op_count count 1 sub def
userdict begin
/q { gsave } bind def
/Q { grestore } bind def
/cm { 6 array astore concat } bind def
/w { setlinewidth } bind def
/J { setlinecap } bind def
/j { setlinejoin } bind def
/M { setmiterlimit } bind def
/d { setdash } bind def
/m { moveto } bind def
/l { lineto } bind def
/c { curveto } bind def
/h { closepath } bind def
/re { exch dup neg 3 1 roll 5 3 roll moveto 0 rlineto
0 exch rlineto 0 rlineto closepath } bind def
/S { stroke } bind def
/f { fill } bind def
/f* { eofill } bind def
/n { newpath } bind def
/W { clip } bind def
/W* { eoclip } bind def
/BT { } bind def
/ET { } bind def
/pdfmark where { pop globaldict /?pdfmark /exec load put }
{ globaldict begin /?pdfmark /pop load def /pdfmark
/cleartomark load def end } ifelse
/BDC { mark 3 1 roll /BDC pdfmark } bind def
/EMC { mark /EMC pdfmark } bind def
/cairo_store_point { /cairo_point_y exch def /cairo_point_x exch def } def
/Tj { show currentpoint cairo_store_point } bind def
/TJ {
{
dup
type /stringtype eq
{ show } { -0.001 mul 0 cairo_font_matrix dtransform rmoveto } ifelse
} forall
currentpoint cairo_store_point
} bind def
/cairo_selectfont { cairo_font_matrix aload pop pop pop 0 0 6 array astore
cairo_font exch selectfont cairo_point_x cairo_point_y moveto } bind def
/Tf { pop /cairo_font exch def /cairo_font_matrix where
{ pop cairo_selectfont } if } bind def
/Td { matrix translate cairo_font_matrix matrix concatmatrix dup
/cairo_font_matrix exch def dup 4 get exch 5 get cairo_store_point
/cairo_font where { pop cairo_selectfont } if } bind def
/Tm { 2 copy 8 2 roll 6 array astore /cairo_font_matrix exch def
cairo_store_point /cairo_font where { pop cairo_selectfont } if } bind def
/g { setgray } bind def
/rg { setrgbcolor } bind def
/d1 { setcachedevice } bind def
%%EndProlog
%%Page: 1 1
%%BeginPageSetup
%%PageBoundingBox: 0 -1 482 191
%%EndPageSetup
q 0 -1 482 192 rectclip q
0 190.312 482 -191 re W n
0 g
138.398 190.312 m 138.398 190.312 143.152 165.327 150.398 162.312 c
153.051 144.441 177.504 151.624 188 144.71 c 199.086 145.737 205.23
141.292 216.801 139.913 c 217.07 137.784 218.797 137.109 219.199
135.112 c 230.285 134.948 237.18 141.652 244.801 147.112 c 257.676
156.339 268.598 163.843 285.602 164.71 c 278.391 154.323 265.457
149.655 263.199 134.312 c 265.25 131.562 268.98 130.491 272 128.71 c
270.293 127.753 267.645 127.737 267.199 125.511 c 272.527 123.323
277.188 124.066 280.801 127.112 c 283.711 126.023 286.395 124.706
287.199 121.511 c 285.781 121.331 283.195 122.319 284 119.913 c 287.094
120.339 287.906 118.484 291.199 119.112 c 293.316 120.644 295.824
122.663 296 123.913 c 298.305 121.929 303.098 118.237 302.398 115.913 c
302.566 115.308 298.078 116.737 296 115.112 c 304.789 111.702 306.328
116.441 312 118.312 c 317.023 114.112 319.52 109.558 309.602 111.913 c
310.527 109.109 315.316 110.163 318.398 109.511 c 319.66 113.577
323.641 111.569 324.801 115.112 c 327.176 114.905 330.332 110.484
332.801 107.913 c 330.141 107.105 324.098 109.679 324 106.312 c 328.004
106.851 330.191 105.569 333.602 105.511 c 336.488 106.89 337.082
110.562 341.602 110.312 c 342.789 107.745 348.043 105.054 347.199
103.112 c 346.148 103.218 341.41 103.234 344 102.312 c 350.441 101.472
351.621 105.89 356 107.112 c 358.195 105.066 362.66 101.839 361.602
99.112 c 359.672 98.851 352.457 99.792 354.398 98.312 c 362.703 96.042
366.754 99.538 371.199 103.112 c 373.305 101.218 376.023 99.933 376.801
96.71 c 374.594 95.984 371.184 96.464 369.602 95.112 c 376.629 93.148
378.43 98.362 384 99.913 c 385.59 98.3 387.785 97.296 388.801 95.112 c
386.5 95.277 384.734 94.909 384 93.511 c 389.008 93.569 391.602 96.042
396 96.71 c 397.855 95.636 399.594 94.437 400.801 92.71 c 403.449
94.569 409.75 98.503 410.398 99.112 c 415.512 103.905 430.836 123.718
436 127.913 c 441.164 132.105 458.488 159.292 481.602 163.112 c 481.602
162.312 l 473.781 159.73 468.398 150.577 465.602 147.112 c 462.801
143.644 454.668 127.777 451.199 121.511 c 447.734 115.245 438.188
95.015 437.602 88.71 c 436.879 80.96 438.656 72.952 439.199 66.312 c
439.156 66.827 442.312 51.335 443.199 47.913 c 443.535 46.616 445.57
37.843 445.602 37.511 c 445.691 36.569 457.336 11.609 457.602 11.112 c
458.195 9.995 466.488 3.495 464 0.71 c 463.734 0.71 464.293 -1.981
459.199 3.112 c 456.938 5.374 447.578 9.437 441.602 17.511 c 440.891
18.468 427.332 37.245 423.199 45.511 c 419.066 53.777 410.652 68.171
409.602 70.312 c 408.547 72.452 399.371 86.999 391.199 78.312 c 388.504
78.55 388.879 81.859 386.398 82.312 c 383.543 81.968 382.008 80.304
380.801 78.312 c 377.992 78.171 378.168 81.015 376 81.511 c 370.793
81.921 370.496 77.413 367.199 75.913 c 359.184 83.847 356.504 71.593
352 71.112 c 348.816 70.773 348.742 77.23 344 74.312 c 343.867 72.441
339.262 70.64 338.398 67.112 c 336.719 69.198 333.602 68.71 333.602
68.71 c 333.602 68.71 334.48 70.769 330.398 70.312 c 331.023 68.027
325.422 61.726 322.398 65.511 c 322.684 66.632 321.945 67.929 319.199
67.112 c 319.016 65.761 316.922 62.804 315.199 60.71 c 312.359 61.605
311.18 64.155 306.398 63.112 c 305.957 62.269 304 57.511 304 57.511 c
301.602 55.913 l 301.602 55.913 299.812 57.741 298.398 57.511 c 298.684
58.632 289.926 57.077 287.199 55.112 c 287.648 53.96 288.449 53.159
289.602 52.71 c 286.062 50.648 282.277 48.835 280.801 44.71 c 287.914
32.894 301.207 27.253 312.801 19.913 c 293.059 18.409 274.633 30.257
260 38.312 c 247.047 45.441 231.883 34.495 213.602 32.71 c 196.863
31.077 179.27 32.3 161.602 31.112 c 165.641 22.085 170.508 13.886
179.199 9.511 c 164.629 6.554 152.258 11.991 144 18.312 c 137.281
23.452 133.266 32.593 123.199 34.312 c 118.254 35.155 112.855 33.87 108
34.312 c 65.645 38.155 31.551 55.714 0 73.511 c 0 75.112 l 6.211 79.984
14.445 73.882 24 75.112 c 22.02 80.601 10.141 83.112 7.199 90.312 c
41.668 107.312 74.152 126.292 116.801 135.112 c 123.117 154.128 129.473
173.109 137.602 190.312 c h
138.398 190.312 m f*
Q Q
showpage
%%Trailer
count op_count sub {pop} repeat
countdictstack dict_count sub {end} repeat
cairo_eps_state restore
%%EOF
## Draw a fish on a bunch of points, at a bunch of sizes.
grImport::PostScriptTrace("fish.eps")
fish <- grImport::readPicture("fish.eps.xml")
set.seed(1)
x <- runif(10)
y <- runif(10)
lim <- c(-0.2, 1.2)
plot(x, y, xlim=lim, ylim=lim)
vps <- gridBase::baseViewports()
grid::pushViewport(vps$inner, vps$figure, vps$plot)
w <- runif(10, 0, 0.3)
r <- diff(fish@summary@yscale) / diff(fish@summary@xscale)
for (i in seq_along(x)) {
grImport::grid.picture(fish,
grid::unit(x[[i]], "native"),
grid::unit(y[[i]], "native"),
width=w[[i]], height=w[[i]] * r)
}
grid::popViewport(3)
@flodebarre
Copy link

Awesome, thanks :-)
It looks like you do not need to bother specifying r (line 15) and height (line 21): the aspect ratio of the picture is preserved if you only specify width (at least on my machine).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment