我有一個500個結果的數組,其中1個如果爲true,0個如果爲false,現在我想繪製一個顏色條以更加圖形化地顯示此結果,一個包含500個單元格的水平條,每個條的顏色代表真綠色或虛假紅色。true-false或zero-and-ones數組的熱圖
這可能嗎?我正在嘗試彩條功能,但我無法這樣做。
我有一個500個結果的數組,其中1個如果爲true,0個如果爲false,現在我想繪製一個顏色條以更加圖形化地顯示此結果,一個包含500個單元格的水平條,每個條的顏色代表真綠色或虛假紅色。true-false或zero-and-ones數組的熱圖
這可能嗎?我正在嘗試彩條功能,但我無法這樣做。
您可以使用imagesc
:
myArray = rand(1,500)>.4; %make a random array of zeros and ones
colormap('hot'); %change this to get the desired colors
imagesc(myArray);
set(gca,'ytick',[]) %remove y-axis ticks as they're not representing actual values
這會給你(發的Octave):
更新:如何使它看起來像一個彩條?
colormap('hot');
imagesc(myArray);
set(gca,'ytick',[])
pbaspect([5 1 1]) %set the ratio of x-axis to y-axis
劇情將如下所示:
A [彩條(https://www.mathworks.com/help/matlab/ref/colorbar.html#examples)是一個顯示劇情中所有可能的顏色/值的欄。你確定這是你想要的嗎?這聽起來像你只是想從你的陣列中創建一個圖像。 – beaker
嗨@beaker是的,你是對的。我試着用colorbar,因爲我不知道任何其他函數來試試這個,並且不知道它是否可能。Masoud的答案就是我正在尋找的。感謝您的幫助! – inavas