你好,
我正在使用以下腳本郵政嘗試擴展從腳本創建的熱圖。 當前形式的腳本為所有列一起製作了一個熱圖,但我想要一個單獨的熱圖 PER 列。 換句話說,我想找到某個列的最小值、中值和最大值,然後僅在該列上應用熱圖,然後對下一列執行相同的操作並繼續。
附上以下內容
1. sample_base_table.jmp:這是正在從中提取的樣本數據集。
2.extract_cols.jsl:這是總結要用於熱圖腳本的數據的腳本
3. heatmap.jsl:這個腳本為指定的列做熱圖
問題:
當我運行 extract_cols.jsl 時,我得到了 4 個名為“Untitled X”的新數據表。 然後,當我運行 heatmap.jsl 時,它只能為創建的最後一個 Untitled X 表創建熱圖。 我不明白這是為什麼... 當我查看調試器代碼時,它說“在‘列’的訪問或評估中找不到列”。 但是,我打印了正在使用的列“Median(Values, Mango)”,它顯示出來,所以我不確定發生了什麼(見下面的輸出圖片)。

改進/未來工作:
理想情況下,在我弄清楚為什麼只更新創建的最後一個數據表後,我想將所有這 4 個水果熱圖列連接到一個數據表中,該數據表還包含國家和水果信息。 換句話說,我正在生成 4 (32x3) 個表,我想生成 1 個 (6x32) 表(4 個水果熱圖 + 國家列 + 位置列)。 目前我正在做的方式是使用 JMP Query Builder 進行列連接。
您正在指定
Names Default To Here( 1 );
它為該特定腳本創建了一個單獨的內存命名空間。也就是說,在您的 extract_cols 腳本中,有一個名為“fruit”的列表。如果在您的熱圖腳本中指定
myFruit = fruit[1];
你的熱圖腳本不會知道你的變量fruit。
在您的熱圖腳本中,您將變量“dt”設置為等於當前數據表。根據您的描述,您是在運行 extract_cols 腳本後立即運行 headmap 腳本。在 JMP 中的任何給定時間,只有 1 個數據表是當前活動數據表。因此,當您指定
dt = Current Data Table();
熱圖腳本獲取當前活動數據表,這將是您在 extract_cols 腳本中創建的最後一個數據表
如果您需要將原始數據表引用傳遞給第二個腳本,可能還有其他 4 個數據表引用,這樣做的一種方法是創建一個單獨的命名空間並將引用放入該命名空間。這是對腳本的修改,創建命名空間並將數據表引用放入其中。
Names Default To Here( 1 );
Clear Symbols();
dt = Current Data Table();
if(isnamespace("trans")==0, trans = new namespace("trans"));
trans:theList = {};
insert into(theList,dt);
fruit = {"Apple","Banana","Mango","Orange"};
For(i = 1, i <= N Items(fruit), i++,
obj = dt << Tabulate(
Set Format( Uniform Format( 10, 0 ) ),
Add Table(
Column Table(
Statistics( Median ),
Grouping Columns( :fruits ),
Analysis Columns( :Values )
),
Row Table( Grouping Columns( :Countries, :locations ) )
),
Local Data Filter(
Add Filter(
columns( :fruits),
Where( :fruits == fruit[i] ),
Display( :fruits, N Items( 14 ) )
)
)
);
trans:theList[i+1] = obj<< make into data table;
Current Report() << Close Window
);
然後,您可以在熱圖腳本中引用命名空間以獲取主表引用或命名空間中保存的任何數據表引用。
Names Default To Here( 1 );
Clear Symbols();
dt = trans:thelist[1];
dt << Begin Data Update;
///////////////////////////////////
// Setting Variables for script ///
//rev_scale = "Reverse Scale";
rev_scale =0;
mean_median = 1; //mean=0, median=1
print(mean_median);
///////////////////////////////////
//gets all columns that are continous and stores that in a list as strings.
colList = dt << get column names( continuous, string );
print(colList);
// Create a temporary subset where the columns are the column list, selects all rows,
// invisible makes it so you don't see the datatable on screen since it is temporary
dtsub = dt << subset(columns(colList), selected rows(0),invisible);
// Move the data into a matrix this will be used later to get min, max, median|mean
allData = dtsub << get as matrix;
// Close the no longer needed temporary data table
close(dtsub, nosave);
// Calculate the statistics across the full data matrix
myMax = Maximum(allData);
myMin = Minimum(allData);
if(mean_median == 0,
myMid = Mean(allData),
myMid = Median(allData)
);
print(myMax);
print(myMin);
print(myMid);
print(colList);
// Run for loop over data table with the min, max and median|mean calculated from above
// gradient color scheme needs to be set.
if(rev_scale == 1,
For( i = 1, i <= N Items( colList ), i++,
Eval(
Substitute(
Expr(
Column( __col__ ) <<
set property(
"color gradient",
{"Green Yellow Red",
Range( {__Max__, __Min__, __Mid__} ),"Reverse Scale"}
) << Color Cell by Value( 1 );
),
Expr( __col__ ), colList[i],
Expr( __Max__ ), myMax,
Expr( __Min__ ), myMin,
Expr( __Mid__ ), myMid
)
);
);
,
For( i = 1, i <= N Items( colList ), i++,
Eval(
Substitute(
Expr(
Column( __col__ ) <<
//Column( colList[i] ) <<
set property(
"color gradient",
{"Green Yellow Red",
Range( {__Max__, __Min__, __Mid__} )}
) << Color Cell by Value( 1 );
),
Expr( __col__ ), colList[i],
Expr( __Max__ ), myMax,
Expr( __Min__ ), myMin,
Expr( __Mid__ ), myMid
)
);
);
);
感謝您的輸入!
當我運行您提供的更新後的 extract_cols 腳本時,我收到以下有關 L 值訪問的錯誤消息...

我的錯誤,改變
insert into(theList,dt);
至
insert into(trans:theList,dt);
theList 不存在......但是 trans:theList 存在