問題
我想為出版物創建此圖

解決方案
為了創建垂直方向的陰影/填充和截斷法線曲線,我使用了 Polygon() 圖形函數。挑戰在於能夠輕鬆且重複地創建在圖形上適當縮放和定位的多邊形。我是用這個函數做的
func_VNormalShape = Function( // create a polygon that looks like a vertically oriented normal distribution
{_xloc, _yloc, _xscale = 1, _yscale = 1},
{_VNormShapeX, _VNormShapeY},
// create a vector of y values to use for plotting the shape
_VNormShapeY = ((_yloc - 3 * _yscale) :: (_yloc + 3 * _yscale) :: (_yscale / 10))`;
// create the filled polygon boundary points
_VNormShapeX = V Concat(
J( 61, 1, _xloc ),
_xloc + Sqrt( 2 * Pi() ) * _yscale * _xscale * Normal Density(
Sort Descending( _VNormShapeY ),
_yloc,
_yscale
)
);
_VNormShapeY = V Concat(
_VNormShapeY,
Sort Descending( _VNormShapeY )
);
// substitute into the Polygon(function) the two vectors with the boundary point X and Y values
// and evaluate the function
Eval(
Substitute(
Expr(
Polygon( Expr( shape_x ), Expr( shape_y ) )
),
Expr( shape_x ), _VNormShapeX,
Expr( shape_y ), _VNormShapeY
)
);
); 函數的前兩個參數指定要繪製的分佈的“原點”或位置(即分佈中心底的 (x,y) 位置)。第二個兩個可選參數是分佈大小的縮放比例。默認大小基於標準正態分佈,縮放比例相對於 x 方向和 y 方向。
該函數的結果是一個計算表達式,圖形腳本用於將分佈繪製為多邊形。
例子:
func_VNormalShape(1,3) 為以 x=1、y=3 為中心的垂直方向標準正態分佈創建多邊形語句。
func_VNormalShape(2,4, 0.5, 1.5) 創建以 x=2, y=5 為中心的分佈,但水平寬度按比例縮小 0.5,垂直寬度按比例放大 1.5。
討論
這是創建整體圖形的一部分的完整腳本。我將這個腳本的輸出保存為一個圖像文件,然後導入到 powerpoint 中添加一些註釋,得到了帖子頂部顯示的圖形
names default to here(1);
func_VNormalShape = Function( // create a polygon that looks like a vertically oriented normal distribution
{_xloc, _yloc, _xscale = 1, _yscale = 1},
{_VNormShapeX, _VNormShapeY},
// create a vector of y values to use for plotting the shape
_VNormShapeY = ((_yloc - 3 * _yscale) :: (_yloc + 3 * _yscale) :: (_yscale / 10))`;
// create the filled polygon boundary points
_VNormShapeX = V Concat(
J( 61, 1, _xloc ),
_xloc + Sqrt( 2 * Pi() ) * _yscale * _xscale * Normal Density(
Sort Descending( _VNormShapeY ),
_yloc,
_yscale
)
);
_VNormShapeY = V Concat(
_VNormShapeY,
Sort Descending( _VNormShapeY )
);
// substitute into the Polygon(function) the two vectors with the boundary point X and Y values
// and evaluate the function
Eval(
Substitute(
Expr(
Polygon( Expr( shape_x ), Expr( shape_y ) )
),
Expr( shape_x ), _VNormShapeX,
Expr( shape_y ), _VNormShapeY
)
);
);
_nw=new window("Figure",
_ob=Outline Box("Figure",
_gb=Graph Box(
suppressaxes,
x scale(0,5),
y scale(-1,11),
Xname(""),
Yname(""),
fill color("gray");
func_VNormalShape(1, 8, .75, .75);
line({1,8}, {1.75, 8});
func_VNormalShape(2, 6, .75, .75);
line({2,6}, {2.75, 6});
func_VNormalShape(3, 4, .75, .75);
line({3,4}, {3.75, 4});
func_VNormalShape(4, 2, .75, .75);
line({4,2}, {4.75, 2});
linestyle(1);
Pen Size(2);
line({0.5, 5}, {4.5, 5});
)
)
);
_gb[FrameBox(1)]<<{top(0), bottom(0), left(0), right(0)};結果輸出:

也可以看看
想單獨分享一遍,今天拔出來做圖的時候真的很方便。