是否可以创建一张看起来像这样的图片?
我解决了一个问题,也要求绘制类似的图片。我不想通过插入手绘图片来破坏我的文档(见下文)。任何见解都将不胜感激。
答案1
这是第一次尝试元帖子,尽管它实际上并不是制作三维图表的最佳工具。
该图表有点“脆弱”——例如,如果您在变换中改变旋转,则需要摆弄法线曲线的倾斜度以使其看起来正确。下面的值是通过反复试验确定的。
prologues := 3;
outputtemplate := "%j%c.eps";
stp = 2.50662827463;
vardef gauss(expr mu,sigma,x) =
if abs(x-mu) < 4sigma:
mexp(-128*(((x-mu)/sigma)**2))/stp/sigma
else:
0
fi
enddef;
vardef gauss_curve(expr mu, sigma, a, b, s) =
(a,gauss(mu,sigma,a)) for x=a+s step s until b: .. (x,gauss(mu,sigma,x)) endfor
enddef;
beginfig(1);
path xx, yy;
u = 1.6mm; v = 0.1mm;
transform t; t = identity rotated -35;
xx = origin -- (50u,0);
yy = origin -- (0,500v) transformed t;
drawarrow xx; drawarrow yy;
label.rt (btex $x$ etex, point infinity of xx);
label.top(btex $y$ etex, point infinity of yy);
for x=10 step 10 until 40:
draw yy shifted (x*u,0) withcolor .8 white;
draw (up--down) transformed t shifted (x*u,0);
label.bot(decimal x, (x*u,0));
endfor
for y=100 step 100 until 400:
draw xx shifted ((0,y*v) transformed t) withcolor .8 white;
draw (left--right) shifted ((0,y*v) transformed t);
label.lft(decimal y, (0,y*v) transformed t);
endfor
path fit; fit = (0,225v) transformed t shifted (5u,0)
-- (0,425v) transformed t shifted (45u,0);
draw fit withcolor .67 red;
for x=10,20,40:
draw gauss_curve(0,1,-2.5,+2.5,.1) slanted 3.6 rotated 90 xscaled 30 yscaled 10
transformed t
shifted ((0,(200+5x)*v) transformed t) shifted (x*u,0)
withcolor .6 white + .2 red;
draw (origin -- 20 up)
shifted ((0,(200+5x)*v) transformed t) shifted (x*u,0)
withcolor .6 white + .2 red;
endfor
endfig;
end.