版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
MetaPost是一个专用的绘制数学类图形的 latex 包
官网:
https://www.tug.org/metapost.html
user manual 下载:
https://www.tug.org/docs/metapost/mpman.pdf
以下是一个可以实现实时绘图脚本实时预览的网站:
http://www.tlhiv.org/mppreview/
绘制箭头图
我们输入一段代码:
drawarrow(0,45)--(0,0); drawarrow(5,45)--(45,0) dashed evenly withcolor blue; drawarrow(5,-2.5)--(45,-2.5); drawarrow(5,-5)--(45,-5);label(btex $X$ etex,(0,50));label(btex $Y$ etex,(0,-3.5));label(btex $Z$ etex,(50,-3.5));
得到效果图:
绘制函数图像
numeric ux, uy;120ux=1.2in;4uy=2.4in; draw(0,4uy)--(0,0)--(120ux,0); pickup pencircle scaled1pt; draw(0,uy){right}for ix=1 upto8:..(15ix*ux, uy*2/(1+cosd15ix)) endfor; label.bot(btex $x$ axis etex,(60ux,0)); label.lft(btex $y$ axis etex rotated90,(0,2uy)); label.lft(btex $\displaystyle y=\frac{2}{1+\cos x} $ etex,(120ux,4uy));
效果图:
在这里插入代码片
画圆
draw(0,0)..(10,0)..(0,0);
预览
画矩形
draw(0,0)--(10,0)--(10,10)--(0,10)--(0,0);
预览
注意:
--绘制的是直线,..绘制的是光滑曲线
设置颜色
drawoptions(withcolor red); draw(0,0)..(10,0)..(0,0);
设置虚线
draw(0,0)..(10,0)..(0,0)dashed(dashpattern(on1 off1)) withcolor red;
预览
调节线宽
draw(0,0)..(10,0)..(0,0)dashed(dashpattern(on1 off1)) withcolor red withpen pencircle scaled0.2pt; draw(0,0)..(20,0)..(0,0)dashed(dashpattern(on1 off1)) withcolor blue withpen pencircle scaled1pt;
预览