cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
SpannerHead
Level IV

Auto Scaling

Following up with this.

 

https://community.jmp.com/t5/Discussions/Automatic-Scaling-Matching-X-and-Y-Axes/m-p/762890#M94321

 

I discovered a flaw in the script whereby excluded rows are not plotted but still factor in the graph scaling.  I need a way to eliminate those from y_there and x_there somehow.

 

dt = Current Data Table();
dt << Clear Column Selection();
colList = dt << get column names( string );
check_list = {"VT", "ID", "DI", "IK", "GM"};
New Window( "Select Variables",
	<<Modal,
	<<On Validate( window:validated ),
	window:enable function = Function( {},
		{Default Local},
		X = window:lbMajor << Get Selected;
		Y = window:lbMinor << Get Selected;
		If( N Items( X ) & N Items( Y ) & X != Y,
			window:validated = 1,
			window:validated = 0
		);
		window:ok button << Enable( window:validated );
	);
	H List Box(
		V List Box(
			Text Box( "Select X Variable" ),
			window:lbMajor = List Box(
				check_list,
				<<Set Max Selected( 1 ),
				enable function
			)
		),
		V List Box(
			Text Box( "Select Y Variable" ),
			window:lbMinor = List Box(
				check_list,
				<<Set Max Selected( 1 ),
				enable function
			)
		)
	);,
	H List Box(
		window:ok button = Button Box( "OK",
			X = window:lbMajor << Get Selected;
			Y = window:lbMinor << Get Selected;
			If( N Items( X ) & N Items( Y ) & X != Y,
				window:validated = 1,
				window:validated = 0
			);
			If( window:validated,
				Print( "Processing with X: " || Char( X ) || ", Y: " || Char( Y ) );
				Window( "Select Variables" ) << Close Window;
			,
				Beep();
				Show( "Invalid Selection" );
				{window:lbMajor, window:lbMinor} << Select;
				window:lbMajor << Inval << Update Window;
				Wait( 0.25 );
				{window:lbMajor, window:lbMinor} << DeSelect;
				window:lbMajor << Inval << Update Window;
				Wait( 0.25 );
				{window:lbMajor, window:lbMinor} << Select;
				window:lbMajor << Inval << Update Window;
				Wait( 0.25 );
				{window:lbMajor, window:lbMinor} << DeSelect;
				window:lbMajor << Inval << Update Window;
			);,
			<<Enable( 0 )
		),
		Button Box( "Cancel", Throw( "!Canceled Analysis" ) )
	)
);
If(
	X[1] == "VT", Xparam = "VT",
	X[1] == "ID", Xparam = "ID",
	X[1] == "DI", Xparam = "DI",
	X[1] == "IK", Xparam = "IK",
	X[1] == "GM", Xparam = "GM"
);
If(
	Y[1] == "VT", Yparam = "VT",
	Y[1] == "ID", Yparam = "ID",
	Y[1] == "DI", Yparam = "DI",
	Y[1] == "IK", Yparam = "IK",
	Y[1] == "GM", Yparam = "GM"
);
Show( Xparam );
Show( Yparam );
For( i = 1, i <= N Cols( dt ), i++,
	If(
		Contains( Munger( Head Name( As Namespace( colList[i] ) ), 0, 2 ), Xparam )
		 & Contains(
			Head Name( As Namespace( colList[i] ) ),
			"% Delta From Target"
		),
		Column( colList[i] ) << Set Selected( 1 )
	)
);
target = dt << get selected columns();
found_list = {};
Show( target );
New Window( "Compilation",
	For( j = 1, j <= N Items( target ), j++,
		Notes = target[j] << Get Property( "Notes" );
		If(
			Contains(
				Munger( Head Name( As Namespace( target[j] ) ), 0, 2 ),
				Xparam
			),
			Connected = Substitute( Head Name( As Namespace( target[j] ) ),
				Xparam, Yparam
			);
			Insert Into( found_list, Connected );
			Try(
				biv = Bivariate(
					Y( Column( dt, found_list[j] ) ),
					X( Column( dt, target[j] ) ),
					Automatic Recalc( 1 ),
					SendToReport(
						Dispatch(
							{},
							"Bivar Plot",
							FrameBox,
							{Frame Size( 470, 470 ),
							Add Text Annotation(
								Text( "Category: " || Notes ),
								Fixed Size( 0 ),
								Filled( 0 ),
								Font( "Segoe UI", 10, "Bold" )
							), Add Graphics Script(
								2,
								Description( "" ),
								Transparency( 0.5 );
								Pen Color( "Black" );
								Fill Color( "Red" );
								Oval( -100, -100, 100, 100, 1 );
								Pen Color( "Black" );
								Fill Color( "Green" );
								Oval( -90, -90, 90, 90, 1 );
								Pen Color( "Black" );
								Fill Color( "Blue" );
								Oval( -80, -80, 80, 80, 1 );
								Pen Color( "Black" );
								Line( [-110 0 110], [0 0 0] );
								Line( [0 0 0], [-110 0 110] );
								Oval( -80, -80, 80, 80 );
								Oval( -90, -90, 90, 90 );
								Oval( -100, -100, 100, 100 );
							)}
						)
					)
				);
				ms = Report( biv )[FrameBox( 1 )] << Find Seg( Marker Seg( 1 ) );
				xs = ms << Get X Values |/ 110;
				ys = ms << Get Y Values |/ 110;
				x_there = Loc( !Is Missing( xs ) );
				y_there = Loc( !Is Missing( ys ) );
				ind = Associative Array( x_there );
				ind << Intersect( Associative Array( y_there ) );
				ind = Matrix( ind << Get Keys );
				xs = xs[ind];
				ys = ys[ind];
				val = Max( Max( Abs( xs ) ), Max( Abs( ys ) ) );
				xaxis = Report( biv )[AxisBox( 1 )];
				yaxis = Report( biv )[AxisBox( 2 )];
				xaxis << Min( -1 * val ) << Max( val );
				yaxis << Min( -1 * val ) << Max( val );
			);
		);
	)
);

 

Help appreciated. 


Slán



SpannerHead
2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Auto Scaling

If marker segment still has those rows but excluded, you should be able to use them in similar manner as you would for values you get from columns. And if they aren't even there, then there should be nothing to worry about. If necessary you could also utilize << Get Row Numbers with marker segment if it is available.

 

Also maybe you could just utilize the columns, values stored in those and ignore marker segment as you know the column names.

-Jarmo

View solution in original post

SpannerHead
Level IV

Re: Auto Scaling

Jarmo

 

I modified the script with your suggestions and it works except in a very isolated case where the data has an odd interdigitisation resulting from a transpose.

 

dt = Current Data Table();
dt << Clear Column Selection();
colList = dt << get column names( string );
check_list = {"VT", "ID", "DI", "IK", "GM"};
New Window( "Select Variables",
	<<Modal,
	<<On Validate( window:validated ),
	window:enable function = Function( {},
		{Default Local},
		X = window:lbMajor << Get Selected;
		Y = window:lbMinor << Get Selected;
		If( N Items( X ) & N Items( Y ) & X != Y,
			window:validated = 1,
			window:validated = 0
		);
		window:ok button << Enable( window:validated );
	);
	H List Box(
		V List Box(
			Text Box( "Select X Variable" ),
			window:lbMajor = List Box(
				check_list,
				<<Set Max Selected( 1 ),
				enable function
			)
		),
		V List Box(
			Text Box( "Select Y Variable" ),
			window:lbMinor = List Box(
				check_list,
				<<Set Max Selected( 1 ),
				enable function
			)
		)
	);,
	H List Box(
		window:ok button = Button Box( "OK",
			X = window:lbMajor << Get Selected;
			Y = window:lbMinor << Get Selected;
			If( N Items( X ) & N Items( Y ) & X != Y,
				window:validated = 1,
				window:validated = 0
			);
			If( window:validated,
				Print( "Processing with X: " || Char( X ) || ", Y: " || Char( Y ) );
				Window( "Select Variables" ) << Close Window;
			,
				Beep();
				Show( "Invalid Selection" );
				{window:lbMajor, window:lbMinor} << Select;
				window:lbMajor << Inval << Update Window;
				Wait( 0.25 );
				{window:lbMajor, window:lbMinor} << DeSelect;
				window:lbMajor << Inval << Update Window;
				Wait( 0.25 );
				{window:lbMajor, window:lbMinor} << Select;
				window:lbMajor << Inval << Update Window;
				Wait( 0.25 );
				{window:lbMajor, window:lbMinor} << DeSelect;
				window:lbMajor << Inval << Update Window;
			);,
			<<Enable( 0 )
		),
		Button Box( "Cancel", Throw( "!Canceled Analysis" ) )
	)
);
If(
	X[1] == "VT", Xparam = "VT",
	X[1] == "ID", Xparam = "ID",
	X[1] == "DI", Xparam = "DI",
	X[1] == "IK", Xparam = "IK",
	X[1] == "GM", Xparam = "GM"
);
If(
	Y[1] == "VT", Yparam = "VT",
	Y[1] == "ID", Yparam = "ID",
	Y[1] == "DI", Yparam = "DI",
	Y[1] == "IK", Yparam = "IK",
	Y[1] == "GM", Yparam = "GM"
);
Show( Xparam );
Show( Yparam );
For( i = 1, i <= N Cols( dt ), i++,
	If(
		Contains( Munger( Head Name( As Namespace( colList[i] ) ), 0, 2 ), Xparam )
		 & Contains(
			Head Name( As Namespace( colList[i] ) ),
			"% Delta From Target"
		),
		Column( colList[i] ) << Set Selected( 1 )
	)
);
non_excluded_rows = dt << get rows where(!Excluded());
target = dt << get selected columns();
found_list = {};
Show( target );
New Window( "Compilation",
	For( j = 1, j <= N Items( target ), j++,
		Notes = target[j] << Get Property( "Notes" );
		If(
			Contains(
				Munger( Head Name( As Namespace( target[j] ) ), 0, 2 ),
				Xparam
			),
			Connected = Substitute( Head Name( As Namespace( target[j] ) ),
				Xparam, Yparam
			);
			Insert Into( found_list, Connected );
			Try(
				biv = Bivariate(
					Y( Column( dt, found_list[j] ) ),
					X( Column( dt, target[j] ) ),
					Automatic Recalc( 1 ),
					SendToReport(
						Dispatch(
							{},
							"Bivar Plot",
							FrameBox,
							{Frame Size( 470, 470 ),
							Add Text Annotation(
								Text( "Category: " || Notes ),
								Fixed Size( 0 ),
								Filled( 0 ),
								Font( "Segoe UI", 10, "Bold" )
							), Add Graphics Script(
								2,
								Description( "" ),
								Transparency( 0.5 );
								Pen Color( "Black" );
								Fill Color( "Red" );
								Oval( -100, -100, 100, 100, 1 );
								Pen Color( "Black" );
								Fill Color( "Green" );
								Oval( -90, -90, 90, 90, 1 );
								Pen Color( "Black" );
								Fill Color( "Blue" );
								Oval( -80, -80, 80, 80, 1 );
								Pen Color( "Black" );
								Line( [-110 0 110], [0 0 0] );
								Line( [0 0 0], [-110 0 110] );
								Oval( -80, -80, 80, 80 );
								Oval( -90, -90, 90, 90 );
								Oval( -100, -100, 100, 100 );
							)}
						)
					)
				);
				ms = Report( biv )[FrameBox( 1 )] << Find Seg( Marker Seg( 1 ) );
				xs = ms << Get X Values |/ 110;
				ys = ms << Get Y Values |/ 110;
				x_there = Loc( !Is Missing( xs[non_excluded_rows] ) );
				y_there = Loc( !Is Missing( ys[non_excluded_rows] ) );
				ind = Associative Array( x_there );
				ind << Intersect( Associative Array( y_there ) );
				ind = Matrix( ind << Get Keys );
				xs = xs[ind];
				ys = ys[ind];
				val = Max( Max( Abs( xs|/ 110 ) ), Max( Abs( ys|/ 110 ) ) );
				xaxis = Report( biv )[AxisBox( 1 )];
				yaxis = Report( biv )[AxisBox( 2 )];
				xaxis << Min( -1 * val ) << Max( val );
				yaxis << Min( -1 * val ) << Max( val );
			);
		);
	)
);

Slán



SpannerHead

View solution in original post

4 REPLIES 4
jthi
Super User

Re: Auto Scaling

You can "pre-filter" your values, for example by getting non-excluded rows first

Names Default To Here(1); 

dt = open("$SAMPLE_DATA/Big Class.jmp");
dt << Select Rows(Index(7, 11)) << Hide and Exclude(1);


non_excluded_rows = dt << get rows where(!Excluded());


m = Column(dt, "height") << get values;

valid_m = m[non_excluded_rows];

N Items(valid_m);

show(valid_m, N Items(valid_m));

 

-Jarmo
SpannerHead
Level IV

Re: Auto Scaling

Nice script as usual!  Some useful things for sure.  Because my original script is not operating on columns directly and I'm using an associative array (I'm new to those) I can't obviously see where to interrupt my code to make the modification?


Slán



SpannerHead
jthi
Super User

Re: Auto Scaling

If marker segment still has those rows but excluded, you should be able to use them in similar manner as you would for values you get from columns. And if they aren't even there, then there should be nothing to worry about. If necessary you could also utilize << Get Row Numbers with marker segment if it is available.

 

Also maybe you could just utilize the columns, values stored in those and ignore marker segment as you know the column names.

-Jarmo
SpannerHead
Level IV

Re: Auto Scaling

Jarmo

 

I modified the script with your suggestions and it works except in a very isolated case where the data has an odd interdigitisation resulting from a transpose.

 

dt = Current Data Table();
dt << Clear Column Selection();
colList = dt << get column names( string );
check_list = {"VT", "ID", "DI", "IK", "GM"};
New Window( "Select Variables",
	<<Modal,
	<<On Validate( window:validated ),
	window:enable function = Function( {},
		{Default Local},
		X = window:lbMajor << Get Selected;
		Y = window:lbMinor << Get Selected;
		If( N Items( X ) & N Items( Y ) & X != Y,
			window:validated = 1,
			window:validated = 0
		);
		window:ok button << Enable( window:validated );
	);
	H List Box(
		V List Box(
			Text Box( "Select X Variable" ),
			window:lbMajor = List Box(
				check_list,
				<<Set Max Selected( 1 ),
				enable function
			)
		),
		V List Box(
			Text Box( "Select Y Variable" ),
			window:lbMinor = List Box(
				check_list,
				<<Set Max Selected( 1 ),
				enable function
			)
		)
	);,
	H List Box(
		window:ok button = Button Box( "OK",
			X = window:lbMajor << Get Selected;
			Y = window:lbMinor << Get Selected;
			If( N Items( X ) & N Items( Y ) & X != Y,
				window:validated = 1,
				window:validated = 0
			);
			If( window:validated,
				Print( "Processing with X: " || Char( X ) || ", Y: " || Char( Y ) );
				Window( "Select Variables" ) << Close Window;
			,
				Beep();
				Show( "Invalid Selection" );
				{window:lbMajor, window:lbMinor} << Select;
				window:lbMajor << Inval << Update Window;
				Wait( 0.25 );
				{window:lbMajor, window:lbMinor} << DeSelect;
				window:lbMajor << Inval << Update Window;
				Wait( 0.25 );
				{window:lbMajor, window:lbMinor} << Select;
				window:lbMajor << Inval << Update Window;
				Wait( 0.25 );
				{window:lbMajor, window:lbMinor} << DeSelect;
				window:lbMajor << Inval << Update Window;
			);,
			<<Enable( 0 )
		),
		Button Box( "Cancel", Throw( "!Canceled Analysis" ) )
	)
);
If(
	X[1] == "VT", Xparam = "VT",
	X[1] == "ID", Xparam = "ID",
	X[1] == "DI", Xparam = "DI",
	X[1] == "IK", Xparam = "IK",
	X[1] == "GM", Xparam = "GM"
);
If(
	Y[1] == "VT", Yparam = "VT",
	Y[1] == "ID", Yparam = "ID",
	Y[1] == "DI", Yparam = "DI",
	Y[1] == "IK", Yparam = "IK",
	Y[1] == "GM", Yparam = "GM"
);
Show( Xparam );
Show( Yparam );
For( i = 1, i <= N Cols( dt ), i++,
	If(
		Contains( Munger( Head Name( As Namespace( colList[i] ) ), 0, 2 ), Xparam )
		 & Contains(
			Head Name( As Namespace( colList[i] ) ),
			"% Delta From Target"
		),
		Column( colList[i] ) << Set Selected( 1 )
	)
);
non_excluded_rows = dt << get rows where(!Excluded());
target = dt << get selected columns();
found_list = {};
Show( target );
New Window( "Compilation",
	For( j = 1, j <= N Items( target ), j++,
		Notes = target[j] << Get Property( "Notes" );
		If(
			Contains(
				Munger( Head Name( As Namespace( target[j] ) ), 0, 2 ),
				Xparam
			),
			Connected = Substitute( Head Name( As Namespace( target[j] ) ),
				Xparam, Yparam
			);
			Insert Into( found_list, Connected );
			Try(
				biv = Bivariate(
					Y( Column( dt, found_list[j] ) ),
					X( Column( dt, target[j] ) ),
					Automatic Recalc( 1 ),
					SendToReport(
						Dispatch(
							{},
							"Bivar Plot",
							FrameBox,
							{Frame Size( 470, 470 ),
							Add Text Annotation(
								Text( "Category: " || Notes ),
								Fixed Size( 0 ),
								Filled( 0 ),
								Font( "Segoe UI", 10, "Bold" )
							), Add Graphics Script(
								2,
								Description( "" ),
								Transparency( 0.5 );
								Pen Color( "Black" );
								Fill Color( "Red" );
								Oval( -100, -100, 100, 100, 1 );
								Pen Color( "Black" );
								Fill Color( "Green" );
								Oval( -90, -90, 90, 90, 1 );
								Pen Color( "Black" );
								Fill Color( "Blue" );
								Oval( -80, -80, 80, 80, 1 );
								Pen Color( "Black" );
								Line( [-110 0 110], [0 0 0] );
								Line( [0 0 0], [-110 0 110] );
								Oval( -80, -80, 80, 80 );
								Oval( -90, -90, 90, 90 );
								Oval( -100, -100, 100, 100 );
							)}
						)
					)
				);
				ms = Report( biv )[FrameBox( 1 )] << Find Seg( Marker Seg( 1 ) );
				xs = ms << Get X Values |/ 110;
				ys = ms << Get Y Values |/ 110;
				x_there = Loc( !Is Missing( xs[non_excluded_rows] ) );
				y_there = Loc( !Is Missing( ys[non_excluded_rows] ) );
				ind = Associative Array( x_there );
				ind << Intersect( Associative Array( y_there ) );
				ind = Matrix( ind << Get Keys );
				xs = xs[ind];
				ys = ys[ind];
				val = Max( Max( Abs( xs|/ 110 ) ), Max( Abs( ys|/ 110 ) ) );
				xaxis = Report( biv )[AxisBox( 1 )];
				yaxis = Report( biv )[AxisBox( 2 )];
				xaxis << Min( -1 * val ) << Max( val );
				yaxis << Min( -1 * val ) << Max( val );
			);
		);
	)
);

Slán



SpannerHead