我有一個包含相關系數統計資料的一維陣列 X,我想繪制一個彩色直方圖。我使用以下代碼:
histogram(X,10)
它可以創建單色直方圖,現在我想繪制一個直方圖,每個單條都有不同的顏色。但“FaceColor”選項只能調整整個繪圖的總顏色。誰能告訴我如何實作這一目標?
uj5u.com熱心網友回復:
您沒有對histogram物件的那種級別的控制,而是您必須使用一個bar繪圖,其中每個條形的高度最好用histcounts.
[h,edges] = histcounts(x,10); % calculate the histogram data
b = bar( (edges(1:end-1) edges(2:end))/2, h ); % plot the bar chart
b.BarWidth = 1; % make the bars full width to look the same as 'histogram'
b.CData = parula( 10 ); % generate colours as a 10x3 array (columns are RGB), can
% do this manually if you want
b.FaceColor = 'flat'; % Make 'bar' use the CData colours

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/440855.html
