JSL 能否用于自动绘制图表并添加参考线等你好,
我定期绘制分布图。有时我只获得几列数据,有时则更多。
生成各个图表后,我需要调整它们各自的最小/最大 Y 轴以提高可读性,然后添加几条参考线(基本上是 USL 和 LSL 线)。过了一段时间,就变得乏味了,尤其是有很多列数据。
我想看看是否有任何方法可以自动化此过程,因为该过程本身相对简单且重复。 我认为 JSL 脚本可以成为这里的解决方案(我对脚本非常陌生)。
这就是我希望脚本执行的操作:
1. 每列数据由5个数据点组成,第一行和第二行分别包含USL和LSL
2. 该脚本应读取所有数据列
3. 绘制所有数据的单独分布图
4.添加USL和LSL参考线(这里可以设置线的粗细和颜色吗?)
5.然后将Y轴的Min更改为LSL-0.003,将Y轴的Max更改为USL为USL+0.003
JSL可以做到以上吗?
谢谢你!
自动化和脚本编写回复:JSL 能否用于自动绘制图表并添加参考线等简短回答:JSL 可以做到这一点。
回复:JSL 能否用于自动绘制图表并添加参考线等- 欢迎来到社区
- 是的,JMP 脚本可以轻松执行您概述的任务。
- JMP 将自动在每个图表上显示您的 USL 和 LSL 值。但是,您描述的数据结构不是 JMP 的正常结构。将 JSL 添加到脚本中以获取 USL 和 LSL 数据并将其移动到每列的规格限制列属性中,然后删除数据的前 2 行是一件相当简单的事情。
- 您的数据描述似乎表明每列数据只有 3 个数据点。(5 个数据点减去 LSL 和 USL 行)并从中绘制分布图。使用 JMP 术语,分布图是直方图显示。这是您指定为您需要的图表吗?如果是这样,如何从 3 个数据点创建此图表。
- 更改轴的最小值和最大值非常容易,并且可以添加到脚本中。
- 我对您在最初条目中所描述内容的解释可能是完全错误的。如果您可以提供您正在使用的数据示例以及您需要显示的图表的插图,那就太好了。
- 我建议您花时间浏览 JMP 中“帮助”下拉菜单下的“发现 JMP”文档。
回复:JSL 能否用于自动绘制图表并添加参考线等感谢您的回复。
对于第四部分,我很抱歉我没有很好地解释自己。 需要明确的是,每列中有 7 行数据。 第一行是 LSL,第二行是 USL。 第 3 行到第 7 行是实际数据。
对于第 6 部分,以下是我的示例数据和结果图表:


对于本示例中的图表,还绘制了第一行和第二行数据,但我不希望这样做。 它们分别是 LSL 和 USL。 我通常所做的是不将 LSL 和 USL 包含在数据中。
回复:JSL 能否用于自动绘制图表并添加参考线等这是一个示例脚本,可以生成您想要的内容

Names Default To Here( 1 );
// Create the data table
// dt = open( "<PATH to="" the="" file="" that="" has="" the="" data="https://community.jmp.com/">" );
// Here is the sample data table you provided
dt = New Table( "Example",
Add Rows( 7 ),
New Column( "Data1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [9.5, 10.5, 10, 10.2, 9.7, 9.6, 10.4] )
),
New Column( "Data2",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [4.5, 5.5, 5, 5.1, 5.2, 4.9, 4.7] )
)
);
// Ge all of the numeric column's names
colNameList = dt << get column names( string, continuous );
//Take the data from rows 1 & 2 and create the Spec Limints column property
For Each( {col}, colNameList,
Eval(
Substitute(
Expr(
Column( dt, col ) << set property(
"Spec Limits",
{LSL( _LSL_ ), USL( _USL_ ), Show Limits( 1 )}
)
),
Expr( _LSL_ ), As Column( dt, col )[1],
Expr( _USL_ ), As Column( dt, col )[2]
)
)
);
// Exclude and Hide row 1 & 2 to eliminate them from Distributions
dt << Select rows( {1,2} );
dt << hide and exclude;
// Run the Distribution Platform, having the Spec Limits as
// Column Properties, will insure the proper Min and Max for
// the Y axis
dt << Distribution( column( eval(colNameList) ));</PATH>回复:JSL 能否用于自动绘制图表并添加参考线等哦哇.. 我当然没想到你会写剧本——谢谢!
我看到脚本的前部分是关于创建我之前提供的示例数据表。 如何修改它以便我可以要求脚本指向我选择的现有数据表(我想这是 .jmp 文件)然后运行?
回复:JSL 能否用于自动绘制图表并添加参考线等打开表:脚本编写指南 > 数据表 > 数据表入门(使用打开() )
从用户选择中获取路径选择文件()
回复:JSL 能否用于自动绘制图表并添加参考线等我的想法是我必须合并您在我的其他线程中帮助回答的另一组代码:
If( Is Missing( fn ),
throw(),
// Else Open the selected file
Open( fn )
);
我想打开文件后,我需要将其作为数据表加载? 这意味着使用 dt 语法?
回复:JSL 能否用于自动绘制图表并添加参考线等您使用 Open() 打开数据表, open 然后返回对已打开的数据表的引用(如果成功打开文件),然后将其存储到 dt 变量
dt = Open("myfile.jmp");回复:JSL 能否用于自动绘制图表并添加参考线等我修改了一位贡献者之前共享的脚本(谢谢),以便用户可以选择要打开的数据文件(.jmp)文件:
Names Default To Here( 1 );
// Open a dialog to choose a .jmp file to open
// Get the filename of the .jmp file to open
dt = Pick File("Select a .jmp file to open", "", {"JMP Files|jmp;jsl;jrn", "All Files|*"}, 1, 0, "");
// If the user did not select a file, exit the script
If( Is Missing( dt ),
Throw(),
// Else Open the selected file
Open( dt )
);
// Get all of the numeric column's names
colNameList = dt << get column names( string, continuous );
// Take the data from rows 1 & 2 and create the Spec Limits column property
For Each( {col}, colNameList,
Eval(
Substitute(
Expr(
Column( dt, col ) << set property(
"Spec Limits",
{LSL( _LSL_ ), USL( _USL_ ), Show Limits( 1 )}
)
),
Expr( _LSL_ ), As Column( dt, col )[1],
Expr( _USL_ ), As Column( dt, col )[2]
)
)
);
// Exclude and Hide row 1 & 2 to eliminate them from Distributions
dt << Select rows( {1,2} );
dt << hide and exclude;
// Run the Distribution Platform
dt << Distribution( column( eval(colNameList) ));运行脚本时,我遇到了以下错误:
Send 在访问或评估 'Send' 时期望可编写脚本的对象,dt << /*###*/获取列名(字符串,连续)/*###*/
dt << 获取列名称似乎有问题?
回复:JSL 能否用于自动绘制图表并添加参考线等您将 dt 作为文件路径,因此它是一个字符串。您需要让它引用新打开的文件,如下所示。注意 Open() 语句
Names Default To Here( 1 );
// Open a dialog to choose a .jmp file to open
// Get the filename of the .jmp file to open
dt = Pick File("Select a .jmp file to open", "", {"JMP Files|jmp;jsl;jrn", "All Files|*"}, 1, 0, "");
// If the user did not select a file, exit the script
If( Is Missing( dt ),
Throw(),
// Else Open the selected file
dt = Open( dt )
);
// Get all of the numeric column's names
colNameList = dt << get column names( string, continuous );
// Take the data from rows 1 & 2 and create the Spec Limits column property
For Each( {col}, colNameList,
Eval(
Substitute(
Expr(
Column( dt, col ) << set property(
"Spec Limits",
{LSL( _LSL_ ), USL( _USL_ ), Show Limits( 1 )}
)
),
Expr( _LSL_ ), As Column( dt, col )[1],
Expr( _USL_ ), As Column( dt, col )[2]
)
)
);
// Exclude and Hide row 1 & 2 to eliminate them from Distributions
dt << Select rows( {1,2} );
dt << hide and exclude;
// Run the Distribution Platform
dt << Distribution( column( eval(colNameList) ));回复:JSL 能否用于自动绘制图表并添加参考线等转移到具有更相关标题的新线程。
回复:JSL 能否用于自动绘制图表并添加参考线等这段代码更干净一些:
// Get the filename of the .jmp file to open
filename = Pick File("Select a .jmp file to open", "", {"JMP Files|jmp;jsl;jrn", "All Files|*"}, 1, 0, "");
// If the user did not select a file, exit the script
If( Is Missing( filename ),
Throw(),
// Else Open the selected file
dt = Open( filename )
);