cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Rob
Rob
Level II

Draw line or polygon with respect to second Y axis

Hi everybody,

 

my plot has two y axis. What I would like to do in a script is to draw lines and polygones.

I can draw with respect to the first y axis e.g. by

Polygon( [0,1,2], [1, 1, 3] );

How do I tell JMP that I mean [1, 1, 3] with respect to the second y axis? Can I switch between axis somehow just like the color or line style?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Draw line or polygon with respect to second Y axis

Here is a simple example

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/semiconductor capability.jmp" );

gb = Graph Builder(
	Variables( X( :PNP2 ), Y( :NPN1 ), Y( :PNP1, Position( 1 ), Side( "Right" ) ) ),
	Elements( Points( X, Y( 1 ), Legend( 5 ) ), Points( X, Y( 2 ), Legend( 7 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"PNP1",
			ScaleBox,
			{Format( "Best", 10 ), Min( 100 ), Max( 540.816326530612 ), Inc( 50 ), Minor Ticks( 1 )}
		)
	)
);

NPN1y1 = 110;
NPN1y2 = 122;
PNP1y1 = 300; // Right side reference

x1 = 150;
x2 = 250;
x3 = 600;

Report( gb )[framebox( 1 )] << Add Graphics script(
	leftMin = Report( gb )[AxisBox( 2 )] << get min;
	leftMax = Report( gb )[AxisBox( 2 )] << get max;
	
	rightMin = Report( gb )[AxisBox( 3 )] << get min;
	rightMax = Report( gb )[AxisBox( 3 )] << get max;
	
	xMat = Matrix( x1 ) || Matrix( x2 ) || Matrix( x3 );
	
	// Calculate a left axis reference based upon right axix value
	newMatY = leftMin + (leftMax - leftMin) * (PNP1y1 - rightMin) / (rightMax - rightMin);
	
	yMat = Matrix( NPN1y1 ) || Matrix( NPN1y2 ) || Matrix( NewMatY );
	
	Transparency( 0.5 );
	Fill Color( {1.0, 0.5, 0.0} );
	Polygon( xmat, yMat );
);
Jim

View solution in original post

5 REPLIES 5
txnelson
Super User

Re: Draw line or polygon with respect to second Y axis

I don't see an axis switch, however, you can always get the min and max for the different axis boxes and then interprolate between the 2 scales

Jim
Rob
Rob
Level II

Re: Draw line or polygon with respect to second Y axis

Of course you can always do it manually by transforming coordinates. But things get more complicated when you have at least one nonlinear y axis. I was hoping there is a faster option.

Thanks anyway for confirming there is none. ;-)

txnelson
Super User

Re: Draw line or polygon with respect to second Y axis

I was not implying to do it manually.  I was implying that one does have programatic access to both axes, which would allow one to calculate the Y axis position.

Jim
Rob
Rob
Level II

Re: Draw line or polygon with respect to second Y axis

Oh, so you mean something like
Y value second axis --> Get pixel position in plot window / on screen --> Calculate Y value on first axis with same pixel position?
Do you have an example for me?
txnelson
Super User

Re: Draw line or polygon with respect to second Y axis

Here is a simple example

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/semiconductor capability.jmp" );

gb = Graph Builder(
	Variables( X( :PNP2 ), Y( :NPN1 ), Y( :PNP1, Position( 1 ), Side( "Right" ) ) ),
	Elements( Points( X, Y( 1 ), Legend( 5 ) ), Points( X, Y( 2 ), Legend( 7 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"PNP1",
			ScaleBox,
			{Format( "Best", 10 ), Min( 100 ), Max( 540.816326530612 ), Inc( 50 ), Minor Ticks( 1 )}
		)
	)
);

NPN1y1 = 110;
NPN1y2 = 122;
PNP1y1 = 300; // Right side reference

x1 = 150;
x2 = 250;
x3 = 600;

Report( gb )[framebox( 1 )] << Add Graphics script(
	leftMin = Report( gb )[AxisBox( 2 )] << get min;
	leftMax = Report( gb )[AxisBox( 2 )] << get max;
	
	rightMin = Report( gb )[AxisBox( 3 )] << get min;
	rightMax = Report( gb )[AxisBox( 3 )] << get max;
	
	xMat = Matrix( x1 ) || Matrix( x2 ) || Matrix( x3 );
	
	// Calculate a left axis reference based upon right axix value
	newMatY = leftMin + (leftMax - leftMin) * (PNP1y1 - rightMin) / (rightMax - rightMin);
	
	yMat = Matrix( NPN1y1 ) || Matrix( NPN1y2 ) || Matrix( NewMatY );
	
	Transparency( 0.5 );
	Fill Color( {1.0, 0.5, 0.0} );
	Polygon( xmat, yMat );
);
Jim