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.

0 件のコメント
採用された回答
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 Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!