cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Draw a filled normal distribution
MathStatChem
Level VI

I have had the need on several occasions to create a filled normal distribution curve for use in presentations, training, and publication.  As common and as important as the normal distribution is, you would think you could find this easily as a standard shape or using an internet search, but I've not had much luck in finding what I needed.  

 

JMP has some nice ways to draw lines and geometric shapes on plots using graphics scripts.  If I want a shape that looks like this

MathStatChem_1-1585415545321.png

one way to do it is to create vectors with the coordinate points that defines a polygon, using normal distribution function, and then in the graphics script use that as the argument for the Polygon() function.

 

The function shown below does just that and returns an evaluated expression that can be used in a graphics script

 

 

func_VNormalShape = Function( // create a polygon that looks like a vertically oriented normal distribution
	{_xloc, _yloc, _xscale = 1, _yscale = 1, _range=3, _scaleres=10},
	{_VNormShapeX, _VNormShapeY}, 
	// _xloc, _yloc is the "origin" for the normal curve (centered on Yloc, base of curve at xloc)
	// _xscale is the scale magnification in the x-axis direction
	// _yscale is the scale magnification in the y-axis direction
	// range is the +/- range (in standard deviation) to draws the curve over
	// scalres is the number of points per _yscale to use for determining the polygon.  10 generally works well, but if range is set to be large
	//   then scale_res should probably be increased.
		
		// create a vector of y values to use for plotting the shape
	_VNormShapeY = ((_yloc - _range * _yscale) :: (_yloc + _range * _yscale) :: (_yscale / _scaleres))`;

        
        // create the filled polygon boundary points
	_VNormShapeX = V Concat(
		J( _range*2*_scaleres + 1, 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 vectorw 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 ) );
); 

and then that function can be used inside the Graph Box() function as shown below (which creates the filled normal curve shown above).  

 

 

_nw = New Window( "Vertical Normal Distribution",
	_ob = Outline Box("Gray Vertical Filled Normal Distribution", 
	
		_hlb = H List Box(
			_gb = Graph Box(
				X Scale( 0, 1.1 ),
				Y Scale( 1, 8 ),
				Xname( "" ),
				Yname( "" ),
				Fill Color( "gray" );
				func_VNormalShape( 0, 4.5, 1, 1, 3.4, 8 );
				
			)
		)
	)
);

 

 

The same approach could be applied to other probability distributions.

Recommended Articles