How can you show the RGB color coordinates of crayons in an interesting way using JMP? (Image copyright James A. Alloway, Jr. Used with permission.)How can you show the RGB color coordinates of crayons in an interesting way using JMP? (Image copyright James A. Alloway, Jr. Used with permission.)How can you show the RGB color coordinates of crayons in an interesting way using JMP? (Image copyright James A. Alloway, Jr. Used with permission.)How can you show the RGB color coordinates of crayons in an interesting way using JMP? (Image copyright James A. Alloway, Jr. Used with permission.)如何使用 JMP 以有趣的方式顯示蠟筆的 RGB 顏色坐標? (圖片版權 James A. Alloway, Jr. 經許可使用。)
工程郵袋
第 2 集:我看到你的本色
JMP Systems 工程師時不時地遇到一些有趣的問題,這些問題在某種程度上超出了典型的範圍JMP用法。 這些應用程序通常很聰明,讓人們明白使用數據不僅僅是為了解決業務或技術問題。 下面是來自紐約州的另一位同事的一個例子,我認為分享它會很有趣。
作為志願者工作的一部分,Jim 試圖分析 150 支 Crayola 蠟筆的數據。 他希望向學生展示炫酷的數據可視化,激發他們對 STEAM(科學、技術、工程、藝術與設計和數學)的興趣。
問題
嗨,邁克 [JMP],
我終於有一個問題要問你了。 我正在為 STEAM 演示文稿創建數據集。 對於藝術與設計部分,我有 Crayola 蠟筆(150 行)的數據。 我正在嘗試使用每行(顏色)的顏色坐標(R,G,B)創建一個三元圖。 我可以毫無困難地創建繪圖,但我希望繪圖上的每個標記都是每行中表示的實際顏色。 我已經能夠手動完成此操作,但我認為必須有更簡單的方法(無需編寫腳本)。
在此方向上的任何指導將不勝感激! (此時不著急。)
謝謝。
吉姆 [用戶]
我的回复
試試這個。<附數據表>
好吧……那是一次信息交流,不是嗎?
這是極少數情況下的一個例子,在這種情況下,唯一的方式是向某人展示如何做某事就是實際上做它為他們。 我通常不喜歡這樣做,但有時這是最好的方法。 是的,在這種情況下,答案是腳本。 讓我們花點時間瀏覽一下數據和我所做的。 吉姆提供的數據(可用這裡)看起來像這樣:
Jim's original data tableJim's original data tableJim's original data tableJim's original data table吉姆的原始數據表
我們看到的是蠟筆名稱的列和該顏色的 HSV RGB 坐標。 我實際上並沒有將 HSV 坐標用於我的解決方案。 Jim 想找出一種方法,以編程方式為行狀態分配顏色匹配 RGB 坐標描述的顏色. (如果這聽起來很複雜,堅持下去——還不錯。)這是我發回的數據表:
My data tableMy data tableMy data tableMy data table我的數據表
請注意我包含的表腳本(在左側綠色箭頭旁邊)。 第一個是魔法發生的地方。 其他的是一些有趣的分析,我稍後會講到。
好吧,Tickle Me Pink!
首先,讓我們來看看這個著色業務。 取決於你想做什麼, JMP需要不同格式的 RGB 坐標。 使用單元格顏色(列中顏色名稱的背景)和行狀態顏色需要在 0 和 1 之間縮放 RGB。 因此,因為我試圖對我所做的事情保持透明,所以我創建了一組列(紅色、綠色、藍色)以將 RGB 坐標從 8 位色標 (0-255) 重新縮放到 0 到 1 之間. 表格腳本“Color Cells”會做兩件事。 首先,它使用對於每一行()循環和 :Color名稱 << 顏色單元格()設置單元格顏色的消息。 然後,再次為了透明度(可能是因為我在幾天的時間裡做了這個——老實說,我不記得是哪一個了),我使用了第二個步驟,包括為了()循環使用我創建的列設置行狀態。
Names Default To Here( 1 );
dt = Current Data Table();
dt << Clear Select;
For Each Row(
// get RGB values
red = Column( "Red" )[Row()];
green = Column( "Green" )[Row()];
blue = Column( "Blue" )[Row()];
// color the "sample" column cell with the sample color
:Color Name << Color Cells( RGB Color( red, green, blue ), Row() );
);
For( i = 1, i <= N Rows(), i++,
// get RGB values
red = Column( "Red" )[i];
green = Column( "Green" )[i];
blue = Column( "Blue" )[i];
dt << Select Rows( i );
dt << Colors( RGB Color( red, green, blue ) );
dt << Clear Select;
);
運行此腳本會創建我發回給吉姆的彩色表格。
現在,雖然這張表非常豐富多彩,但使用此類數據確實需要一些強大的可視化效果。 由於 RGB 是三元坐標空間,因此 Ternary Plot 似乎是一個合適的起點:
A Ternary Plot is a good place to start.A Ternary Plot is a good place to start.A Ternary Plot is a good place to start.A Ternary Plot is a good place to start.三元圖是一個很好的起點。
行狀態著色提供了每支蠟筆在 RGB 顏色空間中所處位置的清晰圖片。 我還應該指出買者自負關於此應用程序中三元圖的使用。 嚴格來說,“三元圖”平台期望為每個坐標提供的三個值總和為 1。 當提供的數據不符合此標準時,它會對數據點進行歸一化。 因此,雖然三元圖非常簡潔,但它並不是色彩空間的 100% 準確表示。 然而,由於練習的目的是製作一些能激發 STEAM 興趣的圖形,我認為用一點準確性來換取視覺衝擊力是可以的……
從分析上講,可以使用層次聚類根據顏色的相似程度對蠟筆進行分組。 在這裡,我展示了星座圖,這是我最喜歡的查看樹狀圖的方式,通過在 RGB 空間坐標上運行層次聚類:
A Constellation Plot produced by performing Hierarchical Clustering on the data.A Constellation Plot produced by performing Hierarchical Clustering on the data.A Constellation Plot produced by performing Hierarchical Clustering on the data.A Constellation Plot produced by performing Hierarchical Clustering on the data.通過對數據執行層次聚類生成的星座圖。
從這裡,我可以看到大約有 5 到 7 組顏色。 我將聚類數設置為 5,然後查看平行圖。 集群中的差異很容易看出,集群內的相似性也很容易看出。 我發現有趣的是,柔和和日光顏色被放入它們自己的簇(簇 2 和 3)中。
The pastel and day-glow colors were put into their own clusters (clusters 2 and 3).The pastel and day-glow colors were put into their own clusters (clusters 2 and 3).The pastel and day-glow colors were put into their own clusters (clusters 2 and 3).The pastel and day-glow colors were put into their own clusters (clusters 2 and 3).柔和色和日光色被放入它們自己的簇中(簇 2 和 3)。
您可以使用 k-Means 聚類腳本看到類似的結果。
後記
與往常一樣,在放下一段時間後重新審視某件事會提供一個新的視角。 自從吉姆最初聯繫我以來,我已經多次重新訪問了這個數據集。 我能說什麼? 我是個書呆子,這是一個有趣的小數據集。 首先,在寫這篇文章的過程中,我意識到我把這段代碼寫得比我需要的複雜得多。 整個著色操作可以使用一個單一的對於每一行()環形。 我還可以通過創建列表並轉換列表來簡化編碼,以獲得 JMP 需要的坐標集,而無需創建新列。
Names Default To Here( 1 );
dt = Current Data Table();
dt << Clear Select;
For Each Row(
// get RGB values
r = Column( "R" )[Row()];
g = Column( "G" )[Row()];
b = Column( "B" )[Row()];
rowVal = {r, g, b};
// create a scaled set of colors
rowValS = rowVal/255;
// color the "sample" column cell with the sample color
:Color Name << Color Cells( RGB Color( rowValS ), Row() );
// apply a row state to each row
dt << Select Rows( Row() );
dt << Colors( RGB Color( rowValS ) );
dt << Clear Select;
);
其次,我非常喜歡 Jim 原始數據集中的三元圖(撇開準確性問題)。 這讓我開始思考如果我生成一個空間填充示例來映射 RGB 空間中的所有組合會發生什麼。 我想出的腳本相當複雜。 我將它上傳到文件交換作為RGB 色彩空間映射如果你想看看。 無論如何……它生成的三元圖令人印象深刻。 回想起來,也許我應該將這篇文章命名為“月之暗面”。
This is what happened when I generated a space-filling example that mapped out all the combinations in the RGB space.This is what happened when I generated a space-filling example that mapped out all the combinations in the RGB space.This is what happened when I generated a space-filling example that mapped out all the combinations in the RGB space.This is what happened when I generated a space-filling example that mapped out all the combinations in the RGB space.這就是當我生成一個映射出 RGB 空間中所有組合的空間填充示例時發生的情況。編者按:你讀過我們工程郵袋系列的第一期? 查看 Mike 如何幫助正在使用的用戶JMP決定是否報名參加除雪服務。
作者的話
對於那些再次閱讀這篇文章的人來說,不,你沒有瘋,標題確實改變了一點。我收到了更新標題的請求,以便我們的搜索引擎更容易找到它。我只能猜測這是因為一些搜索引擎是 19 世紀參考圖書館員的現代化身,沒有幽默感。如有任何不便,我們深表歉意。-M