Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- JMP User Community
- :
- Discussions
- :
- Draw projection from one line chart to another

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 4, 2020 3:19 PM
(1104 views)

Hi,

I am trying to draw a vertical and horizontal projection line from one point on line graph and find out intersecting points' coordinates (X and Y) for the second line in the same graph. for now I have been doing this manually by visualizing the graphs, but I am curious if there is way that Jmp can return X/Y value automatically.

In this example - I manually drew red lines from the purple line chart and want to find where it intersects on green and blue lines

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Here is a very simplistic version of a script that will take your example data table, cast a spline fit through each experiment's data points, and then will allow you to draw the lines from experiment 2(blue) to experiment 1(purple), and then across again to experiment 2.

Run the script, and then enter a value into the "Exter X value" input box, and then Click on the "create line"

button. This is a very primitive script, and will only work for X values from about 2.5 to 4. However, it will give you an idea on how you can build what you want.

```
Names Default To Here( 1 );
// Create the sample data table
dt = New Table( "Sample",
Add Rows( 13 ),
New Column( "Experiment",
Character,
"Nominal",
Set Values(
{"exp1", "exp1", "exp1", "exp1", "exp2", "exp2", "exp2", "exp2", "exp3", "exp3", "exp3", "exp3", ""}
)
),
New Column( "V",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [0.55, 0.65, 0.85, 1.1, 0.55, 0.65, 0.85, 1.1, 0.55, 0.65, 0.85, 1.1, .] )
),
New Column( "X-axis",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [2.16, 2.79, 3.66, 4.19, 2.47, 3.13, 4.15, 4.72, 2.35, 2.95, 3.88, 4.36, 3] )
),
New Column( "Y-axis",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1.183, 2.12, 5.28, 11.2, 1.03, 1.85, 4.54, 9.25, 1.07, 1.93, 4.88, 9.74, .] )
)
);
nw = New Window( "Draw Lines",
hlb = H List Box(
// Generate the graph with the curves
Biv = dt << Bivariate( Y( :Name( "Y-axis" ) ), X( :Name( "X-axis" ) ) ),
V List Box(
Spacer Box( size( 1, 30 ) ),
H List Box( tbMain = Text Box( "Enter X value" ), neb = Number Edit Box() ),
Button Box( "Create Line",
start = neb << get;
// Create a list to hold the starting x,y pair
List1a = {};
List1a[1] = start;
// Find the Y value on experiment 2
fit2Y = Spline Eval( start, fitMat2 );
list1a[2] = fit2y;
// Create a list to hold the second x,y pair
list1b = {};
list1b[1] = start;
fit1Y = Spline Eval( start, fitMat1 );
list1b[2] = fit1Y;
// Create a list to hold the third x,y pair, which
// is the same as the second x,y pair
list2a = list1b;
// Create the 4th x,y pair
// to find the final X value, an iteration of the
// experiment 2 spline has to be done until it
// is larger than the experiment 1 Y value
list2b = {};
count = 0;
While( fit2Y < fit1Y | count > 300,
count++;
fit2Y = Spline Eval( start + (.01 * count), fitMat2 );
);
// set the final x,y values
list2b[1] = start + (.01 * count);
list2b[2] = fit1Y;
// Draw the lines
Report( biv )[FrameBox( 1 )] << add graphics script(
Pen Color( "red" );
Pen Size( 2 );
Line( list1a, list1b );
Line( list2a, list2b );
);
)
)
)
);
// add the spline fits and get the prediction matricies for each spline
biv << Fit Where( :Experiment == "exp1", Fit Spline( 0.001, {Line Color( "Purple" ), save coefficients} ) );
fitMat1 = Current Data Table() << get as matrix;
Close( Current Data Table(), nosave );
biv << Fit Where( :Experiment == "exp2", Fit Spline( 0.001, {Line Color( "Medium Dark Blue" ), save coefficients} ) );
fitMat2 = Current Data Table() << get as matrix;
Close( Current Data Table(), nosave );
biv << Fit Where(
:Experiment == "exp3",
Fit Spline( 0.001, {Line Color( "Medium Dark Green" ), save coefficients} )
);
fitMat3 = Current Data Table() << get as matrix;
Close( Current Data Table(), nosave );
```

Jim

5 REPLIES 5

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Draw projection from one line chart to another

The key to being able to do this, is to know what the formula for the line is. JMP can possibly calculate this, given data points, and what curve fit to use....linear, polynomial, spline, etc.

Can you provide more information on your data?

Can you provide more information on your data?

Jim

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Draw projection from one line chart to another

This is the raw data table for the graph. I don't have a formula, I just use connect thorough.

Experiment | V | X-axis | Y-axis |

exp1 | 0.55 | 2.16 | 1.183 |

exp1 | 0.65 | 2.79 | 2.12 |

exp1 | 0.85 | 3.66 | 5.28 |

exp1 | 1.1 | 4.19 | 11.2 |

exp2 | 0.55 | 2.47 | 1.03 |

exp2 | 0.65 | 3.13 | 1.85 |

exp2 | 0.85 | 4.15 | 4.54 |

exp2 | 1.1 | 4.72 | 9.25 |

exp3 | 0.55 | 2.35 | 1.07 |

exp3 | 0.65 | 2.95 | 1.93 |

exp3 | 0.85 | 3.88 | 4.88 |

exp3 | 1.1 | 4.36 | 9.74 |

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Here is a very simplistic version of a script that will take your example data table, cast a spline fit through each experiment's data points, and then will allow you to draw the lines from experiment 2(blue) to experiment 1(purple), and then across again to experiment 2.

Run the script, and then enter a value into the "Exter X value" input box, and then Click on the "create line"

button. This is a very primitive script, and will only work for X values from about 2.5 to 4. However, it will give you an idea on how you can build what you want.

```
Names Default To Here( 1 );
// Create the sample data table
dt = New Table( "Sample",
Add Rows( 13 ),
New Column( "Experiment",
Character,
"Nominal",
Set Values(
{"exp1", "exp1", "exp1", "exp1", "exp2", "exp2", "exp2", "exp2", "exp3", "exp3", "exp3", "exp3", ""}
)
),
New Column( "V",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [0.55, 0.65, 0.85, 1.1, 0.55, 0.65, 0.85, 1.1, 0.55, 0.65, 0.85, 1.1, .] )
),
New Column( "X-axis",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [2.16, 2.79, 3.66, 4.19, 2.47, 3.13, 4.15, 4.72, 2.35, 2.95, 3.88, 4.36, 3] )
),
New Column( "Y-axis",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1.183, 2.12, 5.28, 11.2, 1.03, 1.85, 4.54, 9.25, 1.07, 1.93, 4.88, 9.74, .] )
)
);
nw = New Window( "Draw Lines",
hlb = H List Box(
// Generate the graph with the curves
Biv = dt << Bivariate( Y( :Name( "Y-axis" ) ), X( :Name( "X-axis" ) ) ),
V List Box(
Spacer Box( size( 1, 30 ) ),
H List Box( tbMain = Text Box( "Enter X value" ), neb = Number Edit Box() ),
Button Box( "Create Line",
start = neb << get;
// Create a list to hold the starting x,y pair
List1a = {};
List1a[1] = start;
// Find the Y value on experiment 2
fit2Y = Spline Eval( start, fitMat2 );
list1a[2] = fit2y;
// Create a list to hold the second x,y pair
list1b = {};
list1b[1] = start;
fit1Y = Spline Eval( start, fitMat1 );
list1b[2] = fit1Y;
// Create a list to hold the third x,y pair, which
// is the same as the second x,y pair
list2a = list1b;
// Create the 4th x,y pair
// to find the final X value, an iteration of the
// experiment 2 spline has to be done until it
// is larger than the experiment 1 Y value
list2b = {};
count = 0;
While( fit2Y < fit1Y | count > 300,
count++;
fit2Y = Spline Eval( start + (.01 * count), fitMat2 );
);
// set the final x,y values
list2b[1] = start + (.01 * count);
list2b[2] = fit1Y;
// Draw the lines
Report( biv )[FrameBox( 1 )] << add graphics script(
Pen Color( "red" );
Pen Size( 2 );
Line( list1a, list1b );
Line( list2a, list2b );
);
)
)
)
);
// add the spline fits and get the prediction matricies for each spline
biv << Fit Where( :Experiment == "exp1", Fit Spline( 0.001, {Line Color( "Purple" ), save coefficients} ) );
fitMat1 = Current Data Table() << get as matrix;
Close( Current Data Table(), nosave );
biv << Fit Where( :Experiment == "exp2", Fit Spline( 0.001, {Line Color( "Medium Dark Blue" ), save coefficients} ) );
fitMat2 = Current Data Table() << get as matrix;
Close( Current Data Table(), nosave );
biv << Fit Where(
:Experiment == "exp3",
Fit Spline( 0.001, {Line Color( "Medium Dark Green" ), save coefficients} )
);
fitMat3 = Current Data Table() << get as matrix;
Close( Current Data Table(), nosave );
```

Jim

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Draw projection from one line chart to another

Thanks! that worked. now I just need to figure out how to add loop on this and make it work for N number of experiments.

I am curious about "count > 300", why 300?

I am curious about "count > 300", why 300?

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Draw projection from one line chart to another

just as a safety check....it should be removed

Jim

Article Labels

There are no labels assigned to this post.