cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
  • New JMP features coming to desktops everywhere this September. Sign up to learn more at jmp.com/launch.
Choose Language Hide Translation Bar
BabyDoragon
Level II

How to Replace Original Points with Contour When Using Add Element in JSL Graphs

The JSL code below attempts to use the add Element method to display a Contour plot on the graph on the right side. However, because add Element is an Add Element operation, it cannot remove or replace the original Points format on the right-side graph, resulting in the generated image being different from the figure below. The original Points remain along with the added Contour. Since the X-axis can only be appended afterwards, is there any way to remove the original Points format while still using add Element?
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = dt << Graph Builder(
	Size( 488, 352 ),
	Show Control Panel( 0 ),
	Fit to Window( "Off" ),
	Variables( Y( :weight ), Overlay( :age ) ),
	Elements( Position( 1, 1 ), Points( X, Y, Legend( 21 ) ), Points( X, Y, Legend( 23 ) ) ), 
		//Elements( Position( 2, 1 ), Contour( X, Y, Legend( 22 ) ) ), 
		
		
);
gb << Add Variable( {:height, Role( "X" )} );
gb << Add Variable( {:Height, Role( "X" )} );
gb << Add Element( 1, 1, {Type( "Points" ), X, Y} );
gb << Add Element( 2, 1, {Type( "Contour" ), X, Y} );
BabyDoragon_2-1757498098586.png

螢幕擷取畫面 2025-09-10 185522.png

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to Replace Original Points with Contour When Using Add Element in JSL Graphs

You can remove the point element

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
	Size(488, 352),
	Show Control Panel(0),
	Fit to Window("Off"),
	Variables(Y(:weight), Overlay(:age)),
	Elements(Position(1, 1), Points(X, Y, Legend(21)), Points(X, Y, Legend(23))), 
		//Elements( Position( 2, 1 ), Contour( X, Y, Legend( 22 ) ) ), 
		
		
);
gb << Add Variable({:height, Role("X")});
gb << Add Variable({:Height, Role("X")});
gb << Remove Element(2, 1, 1);
gb << Remove Element(2, 1, 1);
gb << Add Element(2, 1, {Type("Contour"), X, Y});

or you could build the graph builder expression to take this into account

-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: How to Replace Original Points with Contour When Using Add Element in JSL Graphs

You can remove the point element

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
	Size(488, 352),
	Show Control Panel(0),
	Fit to Window("Off"),
	Variables(Y(:weight), Overlay(:age)),
	Elements(Position(1, 1), Points(X, Y, Legend(21)), Points(X, Y, Legend(23))), 
		//Elements( Position( 2, 1 ), Contour( X, Y, Legend( 22 ) ) ), 
		
		
);
gb << Add Variable({:height, Role("X")});
gb << Add Variable({:Height, Role("X")});
gb << Remove Element(2, 1, 1);
gb << Remove Element(2, 1, 1);
gb << Add Element(2, 1, {Type("Contour"), X, Y});

or you could build the graph builder expression to take this into account

-Jarmo
BabyDoragon
Level II

Re: How to Replace Original Points with Contour When Using Add Element in JSL Graphs

I have two questions to ask:
(1) Why are the elements (2, 1, 1) deleted twice?
The first two numbers represent the position in the graph, but I don't yet understand the meaning of the third value.

(2) From the new output graph, I noticed that the X-axis limits for X and Y are different. How can I make the X-axis limits on both the left and right sides the same automatically?

jthi
Super User

Re: How to Replace Original Points with Contour When Using Add Element in JSL Graphs

 

1. You have already added points to your graph even though you do not have x-axis -> you might end up with more Points graphs than you think.

 

 

Run graph builder script -> copy script

 

Graph Builder(
	Size(488, 352),
	Show Control Panel(0),
	Fit to Window("Off"),
	Variables(Y(:weight), Overlay(:age)),
	Elements(Points(Y, Legend(21)), Points(Y, Legend(23)))
);

 

Run << Add Variable -> Copy script

Graph Builder(
	Size(488, 352),
	Show Control Panel(0),
	Fit to Window("Off"),
	Variables(X(:height), Y(:weight), Overlay(:age)),
	Elements(Points(X, Y, Legend(21)), Points(X, Y, Legend(23)))
);

Run << Add Variable -> Copy script

Graph Builder(
	Size(488, 352),
	Show Control Panel(0),
	Fit to Window("Off"),
	Variables(X(:height), X(:height), Y(:weight), Overlay(:age)),
	Elements(Position(1, 1), Points(X, Y, Legend(21)), Points(X, Y, Legend(23))),
	Elements(Position(2, 1), Points(X, Y, Legend(24)), Points(X, Y, Legend(25)))
);

Run << Remove Element -> copy script

 

 

Graph Builder(
	Size(488, 352),
	Show Control Panel(0),
	Fit to Window("Off"),
	Variables(X(:height), X(:height), Y(:weight), Overlay(:age)),
	Elements(Position(1, 1), Points(X, Y, Legend(21)), Points(X, Y, Legend(23))),
	Elements(Position(2, 1), Points(X, Y, Legend(25)))
);

Run << Remove Element -> copy script

 

 

Graph Builder(
	Size(488, 352),
	Show Control Panel(0),
	Fit to Window("Off"),
	Variables(X(:height), X(:height), Y(:weight), Overlay(:age)),
	Elements(Position(1, 1), Points(X, Y, Legend(21)), Points(X, Y, Legend(23))),
	Elements(Position(2, 1))
);

and so on. 

 

 

You can give yourself much better chance of success if you use as complete graph builder as possible

 

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
	Size(488, 393),
	Show Control Panel(0),
	Fit to Window("Off"),
	Variables(X(:height), Y(:weight), Overlay(:age)),
	Elements(Points(X, Y, Legend(2)))
);

gb << Add Variable({:Height, Role("X"), Position(2)});
gb << Remove Element(2, 1, 1);
gb << Add Element(2, 1, {Type("Contour"), X, Y});

 

 

2. You can adjust the x-axis with a script (the axis are different as contour plot needs more space than points)

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
	Size(488, 352),
	Show Control Panel(0),
	Fit to Window("Off"),
	Variables(Y(:weight), Overlay(:age)),
	Elements(Position(1, 1), Points(X, Y, Legend(21)), Points(X, Y, Legend(23))), 
		//Elements( Position( 2, 1 ), Contour( X, Y, Legend( 22 ) ) ), 
		
		
);
gb << Add Variable({:height, Role("X")});
gb << Add Variable({:Height, Role("X")});
gb << Remove Element(2, 1, 1);
gb << Remove Element(2, 1, 1);
gb << Add Element(2, 1, {Type("Contour"), X, Y});

min2 = Report(gb)[AxisBox(3)] << get min;
max2 = Report(gb)[AxisBox(3)] << get max;
Report(gb)[AxisBox(1)] << Min(min2) << Max(max2);

 

-Jarmo

Recommended Articles