[ X, Y, Z ] = peaks(30);
figure(101);
surfc(X, Y, Z);
zlabel('Absolute Values');
%
Z_Scl = 0.01;
Z_Bar = linspace(min(Z(:)), max(Z(:)), 10);
%
colormap jet;
c = colorbar('Location', 'EastOutside', ...
'Ticks', Z_Bar, 'TickLabels', cellstr(num2str(Z_Bar(:)*Z_Scl, '%.3e')));
ylabel(c, 'Relative Values');
對於z值和所述顏色條之間的任意的映射,所以能夠surf
,contourf
和contour
結合如下(由thesetwo偉大的答案啓發):
[ X, Y, Z ] = peaks(30); % Generate data
CB_Z = (sin(Z/max(Z(:))) - cos(Z/max(Z(:)))).^2 + X/5 - Y/7; % Generate colormap
CF_Z = min(Z(:)); % Calculate offset for filled contour plot
CR_Z = max(Z(:)); % Calculate offset for contour plot
%
figure(102); % Create figure
clf(102);
hold on; grid on; grid minor; % Retain current plot and create grid
xlabel('x'); % Create label for x-axis
ylabel('y'); % Create label for y-axis
zlabel('Scaling 1'); % Create label for z-axis
surf(X, Y, Z, CB_Z); % Create surface plot
%
CF_H = hgtransform('Parent', gca); % https://stackoverflow.com/a/24624311/8288778
contourf(X, Y, CB_Z, 20, 'Parent', CF_H); % Create filled contour plot
set(CF_H, 'Matrix', makehgtform('translate', [ 0, 0, CF_Z ])); % https://stackoverflow.com/a/24624311/8288778
%
CR_H = hgtransform('Parent', gca); % https://stackoverflow.com/a/24624311/8288778
contour(X, Y, CB_Z, 20, 'Parent', CR_H); % Create contour plot
set(CR_H, 'Matrix', makehgtform('translate', [ 0, 0, CR_Z ])); % https://stackoverflow.com/a/24624311/8288778
%
colormap jet; % Set current colormap
CB_H = colorbar('Location', 'EastOutside'); % Create colorbar
caxis([ min(CB_Z(:)), max(CB_Z(:)) ]); % Set the color limits for the colorbar
ylabel(CB_H, 'Scaling 2'); % Create label for colorbar
你想在z軸上的值是從c軸不同?這有點誤導... – EBH
@EBH問題已更新,現在清楚還是誤導? – Discbrake
你的意圖甚至在以前很清楚,在我看來,無論是多餘的還是誤導性的,都顯示了2個軸的相同值。但我想這可能對某些可視化有用(我認爲寧願將括號內的一個值放在z軸內,例如'5(0.05)')。 – EBH