Im trying to figure out how to create this image in MetaPost
[Tex/LaTex] How to create MetaPost image for LaTeX
metapost
Related Solutions
For powerful graphics I would recommend Asymptote. It has a C++-type object-oriented syntax and is not that difficult to learn. Some of the main strong points are (but look at the gallery on the webpage):
- Full math and linear algebra engine
- Full 3D including active 3D pictures in PDF
- Use LaTeX to set all text and math
- It can be inlined in Latex but it is normaly better to use it for standalone graphics.
Here is a nice one from the gallery of Asymptote examples by GaƩtan Marris
with the code that generated it
import graph3;
import contour;
import grid3;
import palette;
size(8cm,IgnoreAspect);
currentprojection=orthographic(-10,-10,8);
limits((0,0,0),(5,10,12));
real f(pair z) {return (z.x+z.y)/(2+cos(z.x)*sin(z.y));}
real[] lignesniveaux={2,4,6,8};
surface s=surface(f,(0,0),(5,10),50,Spline);
draw(s,mean(palette(s.map(zpart),Rainbow())),black);
grid3(new grid3routines [] {XYXgrid, ZXgrid(10), ZYgrid(5)},
Step=2,
step=1,
pGrid=new pen[] {red, blue, black},
pgrid=new pen[] {0.5red, lightgray, lightgray});
xaxis3(Label("$x$",position=MidPoint,align=SE),
Bounds(Min,Min),
OutTicks());
yaxis3(Label("$y$",position=MidPoint,align=SW),
Bounds(Min,Min),
OutTicks(Step=2));
zaxis3(Bounds(Max,Both));
zaxis3(Label("$z$",position=EndPoint,align=N+W),
XYEquals(0,10),
InTicks(beginlabel=false,endlabel=false,Label(align=Y)));
draw(lift(f,contour(f,(0,0),(5,10),lignesniveaux)),1bp+red);
Proper Answer
Note I deleted my previous answer, because this is a working solution:
Use the following MP file
beginfig(1);
externalfigure "hacker.jpg" scaled 3cm;
endfig;
end;
and compile it using
mptopdf --metafun filename
This will generate the following filename.1
file:
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 86 86
%%HiResBoundingBox: 0 0 85.03935 85.03935
%%Creator: MetaPost 1.504
%%CreationDate: 2013.04.14:1210
%%Pages: 1
%%BeginProlog
%%BeginResource: procset mpost
/bd{bind def}bind def
/hlw{0 dtransform exch truncate exch idtransform pop setlinewidth}bd
/vlw{0 exch dtransform truncate idtransform setlinewidth pop}bd
/l{lineto}bd/r{rlineto}bd/c{curveto}bd/m{moveto}bd/p{closepath}bd/n{newpath}bd
/C{setcmykcolor}bd/G{setgray}bd/R{setrgbcolor}bd/lj{setlinejoin}bd/ml{setmiterlimit}bd
/lc{setlinecap}bd/S{stroke}bd/F{fill}bd/q{gsave}bd/Q{grestore}bd/s{scale}bd/t{concat}bd
/sd{setdash}bd/rd{[] 0 setdash}bd/P{showpage}bd/B{q F Q}bd/W{clip}bd
%%EndResource
%%EndProlog
%%Page: 1 1
%%MetaPostSpecials: 2.0 123 1000
%%MetaPostSpecial: 9 85.03935 0 0 85.03935 0 0 hacker.jpg 1 10
0.123 0.012 0.001 R
n 0 0 m
0 0 l
0 0 l
0 0 l
p F
P
%%EOF
and a filename-1.pdf
file that includes the image.
Best Answer
UPDATE
I have made some adjustments and added some explanation on the methods used. Note I changed the color names just for compatibility reasons.
This is the old MWE for reference: