我有一個矩陣中5個不同頻率的數據集,我想用plot,hist和mesh來說明它們。然而,每種情節類型使用不同的顏色映射(見圖片),所以我需要每個情節的圖例。Matlab:用於hist,plot和mesh的相同色圖
有沒有辦法爲所有繪圖類型設置相同的顏色映射,或者爲每個繪圖類型指定一個顏色映射?另一件奇怪的事情:例如,我可以使用圖形工具爲hist設置顏色表,但不能用於正常的plot
。對於網格我必須使用hold on
循環,所以我猜這裏設置顏色不同於定義顏色映射?
編輯:
這裏是一個小例子。它仍然不起作用,請參閱下面的代碼中的註釋。
clear all;
close all;
clc;
% make up some data with the original format
freqLen = 5;
data = zeros(10, 3, 3, freqLen);
data(:, :, :, 1) = rand(10, 3, 3);
data(:, :, :, 2) = rand(10, 3, 3)+1;
data(:, :, :, 3) = rand(10, 3, 3)+2;
data(:, :, :, 4) = rand(10, 3, 3)+3;
data(:, :, :, 5) = rand(10, 3, 3)+4;
% reshape data so we get a vector for each frequency
dataF = reshape(data, [10*3*3, freqLen]);
% prepare colors for plot, try to get 5 colors over the range of colormap
% but I get wrong colors using both methods below!
%cols = colormap(jet);
%cols = cols(1:round(length(cols)/length(freqGHz)):end, :);
cols = jet(freqLen);
% plot samples in 3D
figure('Position', [0 0 1000 1000]);
subplot(211);
hold on;
for iF = 1:freqLen
dataThisF = dataF(:, iF);
data3D = reshape(dataThisF, [10*3, 3]);
mesh(data3D);
% try to give each "holded" mesh a different color. Not working!
% after the loop, all meshes have the last color
set(get(gca, 'child'), 'FaceColor', 'w', 'EdgeColor', cols(iF, :));
end
view(60, 20);
% plot samples
subplot(223);
hold on;
for iF = 1:freqLen
% the loop is not avoidable
% because matlab maps the colors wrong when plotting as a matrix
% at least its not using the colormap colors
plot(dataF(:, iF), 'Color', cols(iF, :));
end
% plot histogram
subplot(224);
% actually the only one which is working as intended, horray!
hist(dataF, 50);
我怎麼可以給holded者網單一的顏色,和別人不同?如何在使用簡單線條繪製矩陣時繪製正確的噴射色彩圖,或者至少從噴射色彩圖中獲取5種顏色(jet(5)
給出5種不同的顏色,但不是從頭到尾)?
你能告訴一小段代碼如何創建其中之一嗎?你是否以相同的順序繪製所有數據?即首先10Ghz總是,然後15,... –