Colormap map to Y axis instead of Z

7 次查看(过去 30 天)
I'm using surf() and plot3() to plot a set of magnetic field values centered on their physical position and a reference object on the same plot and a colorbar to show the field strength at that point. The problem I'm having is that the colormap is tied to the Z axis values and I want to make them refer to the Y axis values.
% Plate plane position shiftsurf()
pxShift = -XPMagAvg(1)+(0.08-(1*0.01));
% Main plotting
f = figure;
figure(1);
surf(xzpos,(XPMAG{1}+pxShift), zxpos, 'FaceColor', 'interp');
hold on
plot3(CSC1(:,1),CSC1(:,2),CSC1(:,3),'k', CSC2(:,1),CSC2(:,2),...
CSC2(:,3),'k', CSC3(:,1),CSC3(:,2),CSC3(:,3),'k', ...
CSC4(:,1),CSC4(:,2),CSC4(:,3),'k');
xlabel('X [m]');
ylabel('Y [m]');
zlabel('Z [m]');
title(strcat('XZ Magnetic Field at Height. Avg = ', ...
num2str(XPMagAvg(1))));
% Colorbar and colorbar settings
cbRange = linspace(minXPMM, maxXPMM, 5);
cbR = cell(1,5);
for u = 1:5
cbR{u} = num2str(cbRange(u));
end
cbTickRange = linspace(minXPMM+pxShift, maxXPMM+pxShift, 5);
cbh=colorbar('XTickLabel',{cbR{1},cbR{2},cbR{3},cbR{4}, ...
cbR{5}},'XTick', cbTickRange); % Set colorbar range and ticks
caxis([minXPMM+pxShift maxXPMM+pxShift]); % Change colorbar range
ylabel(cbh, 'B [Gauss]', 'FontSize', 16, 'Rotation', 90);
colormap('parula');
% Window settings
ax = gca;
ax.XLim = [-0.15 0.15];
ax.YLim = [-0.15 0.15];
ax.ZLim = [-0.1 0.1];
f.Units = 'inches';
f.Position = [3 3 10 8];
hold off
hold off
I can change all I need for the normal case where my field is perpendicular to this. So I want something like this in the second pic but perpendicular.

采纳的回答

Voss
Voss 2022-4-16
You can use the fourth input to surf to set the color to something other than Z. In this case set the color to be the same as Y:
load('ColorbarDifferentAxis.mat')
delete(f) % (delete the figure stored in the mat-file so it doesn't show up here)
% Plate plane position shiftsurf()
pxShift = -XPMagAvg(1)+(0.08-(1*0.01));
% Main plotting
f = figure;
figure(1);
% surf(xzpos,(XPMAG{1}+pxShift), zxpos, 'FaceColor', 'interp');
surf(xzpos,(XPMAG{1}+pxShift), zxpos, (XPMAG{1}+pxShift), 'FaceColor', 'interp');
hold on
plot3(CSC1(:,1),CSC1(:,2),CSC1(:,3),'k', CSC2(:,1),CSC2(:,2),...
CSC2(:,3),'k', CSC3(:,1),CSC3(:,2),CSC3(:,3),'k', ...
CSC4(:,1),CSC4(:,2),CSC4(:,3),'k');
xlabel('X [m]');
ylabel('Y [m]');
zlabel('Z [m]');
title(strcat('XZ Magnetic Field at Height. Avg = ', ...
num2str(XPMagAvg(1))));
% Colorbar and colorbar settings
cbRange = linspace(minXPMM, maxXPMM, 5);
cbR = cell(1,5);
for u = 1:5
cbR{u} = num2str(cbRange(u));
end
cbTickRange = linspace(minXPMM+pxShift, maxXPMM+pxShift, 5);
cbh=colorbar('XTickLabel',{cbR{1},cbR{2},cbR{3},cbR{4}, ...
cbR{5}},'XTick', cbTickRange); % Set colorbar range and ticks
caxis([minXPMM+pxShift maxXPMM+pxShift]); % Change colorbar range
ylabel(cbh, 'B [Gauss]', 'FontSize', 16, 'Rotation', 90);
colormap('parula');
% Window settings
ax = gca;
ax.XLim = [-0.15 0.15];
ax.YLim = [-0.15 0.15];
ax.ZLim = [-0.1 0.1];
f.Units = 'inches';
f.Position = [3 3 10 8];
hold off
hold off

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by