cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
%3CLINGO-SUB%20id%3D%22lingo-sub-77396%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EDraw%20line%20or%20polygon%20with%20respect%20to%20second%20Y%20axis%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-77396%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EHi%20everybody%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Emy%20plot%20has%20two%20y%20axis.%20What%20I%20would%20like%20to%20do%20in%20a%20script%20is%20to%20draw%20lines%20and%20polygones.%3C%2FP%3E%3CP%3EI%20can%20draw%20with%20respect%20to%20the%20first%20y%20axis%20e.g.%20by%3C%2FP%3E%3CP%3EPolygon(%20%5B0%2C1%2C2%5D%2C%20%5B1%2C%201%2C%203%5D%20)%3B%3C%2FP%3E%3CP%3EHow%20do%20I%20tell%20JMP%20that%20I%20mean%20%5B1%2C%201%2C%203%5D%20with%20respect%20to%20the%20second%20y%20axis%3F%20Can%20I%20switch%20between%20axis%20somehow%20just%20like%20the%20color%20or%20line%20style%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-77886%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Draw%20line%20or%20polygon%20with%20respect%20to%20second%20Y%20axis%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-77886%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EHere%20is%20a%20simple%20example%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0Adt%20%3D%20Open(%20%22%24SAMPLE_DATA%2Fsemiconductor%20capability.jmp%22%20)%3B%0A%0Agb%20%3D%20Graph%20Builder(%0A%20Variables(%20X(%20%3APNP2%20)%2C%20Y(%20%3ANPN1%20)%2C%20Y(%20%3APNP1%2C%20Position(%201%20)%2C%20Side(%20%22Right%22%20)%20)%20)%2C%0A%20Elements(%20Points(%20X%2C%20Y(%201%20)%2C%20Legend(%205%20)%20)%2C%20Points(%20X%2C%20Y(%202%20)%2C%20Legend(%207%20)%20)%20)%2C%0A%20SendToReport(%0A%20%20Dispatch(%0A%20%20%20%7B%7D%2C%0A%20%20%20%22PNP1%22%2C%0A%20%20%20ScaleBox%2C%0A%20%20%20%7BFormat(%20%22Best%22%2C%2010%20)%2C%20Min(%20100%20)%2C%20Max(%20540.816326530612%20)%2C%20Inc(%2050%20)%2C%20Minor%20Ticks(%201%20)%7D%0A%20%20)%0A%20)%0A)%3B%0A%0ANPN1y1%20%3D%20110%3B%0ANPN1y2%20%3D%20122%3B%0APNP1y1%20%3D%20300%3B%20%2F%2F%20Right%20side%20reference%0A%0Ax1%20%3D%20150%3B%0Ax2%20%3D%20250%3B%0Ax3%20%3D%20600%3B%0A%0AReport(%20gb%20)%5Bframebox(%201%20)%5D%20%26lt%3B%26lt%3B%20Add%20Graphics%20script(%0A%20leftMin%20%3D%20Report(%20gb%20)%5BAxisBox(%202%20)%5D%20%26lt%3B%26lt%3B%20get%20min%3B%0A%20leftMax%20%3D%20Report(%20gb%20)%5BAxisBox(%202%20)%5D%20%26lt%3B%26lt%3B%20get%20max%3B%0A%20%0A%20rightMin%20%3D%20Report(%20gb%20)%5BAxisBox(%203%20)%5D%20%26lt%3B%26lt%3B%20get%20min%3B%0A%20rightMax%20%3D%20Report(%20gb%20)%5BAxisBox(%203%20)%5D%20%26lt%3B%26lt%3B%20get%20max%3B%0A%20%0A%20xMat%20%3D%20Matrix(%20x1%20)%20%7C%7C%20Matrix(%20x2%20)%20%7C%7C%20Matrix(%20x3%20)%3B%0A%20%0A%20%2F%2F%20Calculate%20a%20left%20axis%20reference%20based%20upon%20right%20axix%20value%0A%20newMatY%20%3D%20leftMin%20%2B%20(leftMax%20-%20leftMin)%20*%20(PNP1y1%20-%20rightMin)%20%2F%20(rightMax%20-%20rightMin)%3B%0A%20%0A%20yMat%20%3D%20Matrix(%20NPN1y1%20)%20%7C%7C%20Matrix(%20NPN1y2%20)%20%7C%7C%20Matrix(%20NewMatY%20)%3B%0A%20%0A%20Transparency(%200.5%20)%3B%0A%20Fill%20Color(%20%7B1.0%2C%200.5%2C%200.0%7D%20)%3B%0A%20Polygon(%20xmat%2C%20yMat%20)%3B%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-77880%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Draw%20line%20or%20polygon%20with%20respect%20to%20second%20Y%20axis%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-77880%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EOh%2C%20so%20you%20mean%20something%20like%3CBR%20%2F%3EY%20value%20second%20axis%20--%26gt%3B%20Get%20pixel%20position%20in%20plot%20window%20%2F%20on%20screen%20--%26gt%3B%20Calculate%20Y%20value%20on%20first%20axis%20with%20same%20pixel%20position%3F%3CBR%20%2F%3EDo%20you%20have%20an%20example%20for%20me%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-77879%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Draw%20line%20or%20polygon%20with%20respect%20to%20second%20Y%20axis%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-77879%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EI%20was%20not%20implying%20to%20do%20it%20manually.%26nbsp%3B%20I%20was%20implying%20that%20one%20does%20have%20programatic%20access%20to%20both%20axes%2C%20which%20would%20allow%20one%20to%20calculate%20the%20Y%20axis%20position.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-77878%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Draw%20line%20or%20polygon%20with%20respect%20to%20second%20Y%20axis%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-77878%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EOf%20course%20you%20can%20always%20do%20it%20manually%20by%20transforming%20coordinates.%20But%20things%20get%20more%20complicated%20when%20you%20have%20at%20least%20one%20nonlinear%20y%20axis.%20I%20was%20hoping%20there%20is%20a%20faster%20option.%3C%2FP%3E%3CP%3EThanks%20anyway%20for%20confirming%20there%20is%20none.%20%3CLI-EMOJI%20id%3D%22lia_winking-face%22%20title%3D%22%3Acara_gui%C3%B1ando_un_ojo%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-77408%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Draw%20line%20or%20polygon%20with%20respect%20to%20second%20Y%20axis%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-77408%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EI%20don't%20see%20an%20axis%20switch%2C%20however%2C%20you%20can%20always%20get%20the%20min%20and%20max%20for%20the%20different%20axis%20boxes%20and%20then%20interprolate%20between%20the%202%20scales%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
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