why am I Unable to overplot a line on a surface plot?
조회 수: 3 (최근 30일)
이전 댓글 표시
Why am I unable to correctly overplot a "line" on a "surface" plot?
It becomes cracked as shown in the image below. If one observes clearly, I have tried inserting two white lines with heavy linewidth:
one near y=1 and other at y=5, but it is hardly visible.
the code is as below: (DATA ATTACHED)
surface(t,fby,abs(cfsby)); shading flat;
set(gca,'YScale','log')
xlim([17+25./60 17+28./60]); ylim([0.02,1]);
colormap('jet');
caxis([0 0.05]);
set(gca,...
'YTick', [0.01 0.1 0.2 0.5 1 2 3 4 5], 'YTickLabel',[0.01 0.1 0.2 0.5 1 2 3 4 5]);
% Customize appearance
set(gca, 'XMinorTick', 'on', 'YMinorTick', 'on', 'FontSize', 18, 'fontweight', 'b');
set(gca, 'LineWidth', 2.25, 'TickLength', [0.010 0.010]);
% fo = (q .* B) / (2 * pi_value * m);
q = 1.602e-19; % Charge in Coulombs
mo = 2.657*1e-26;
mhe = 6.64*1e-27;
fo = (q .* by_sc * 1e-9) / (2*pi*mo);
fhe = (q .* by_sc * 1e-9) / (2*pi*mhe);
hold on;
% figure;
plot(t,fhe,'--w','LineWidth',5)
hold on;
plot(t,fo,'--w','LineWidth',2)
Any help is appreciated.
Thanks!
댓글 수: 2
Paul
2024년 11월 24일
Can you upload a .mat file to your question with all of the variables needed to run the code? Use the paperclip icon on the Insert portion of the ribbon.
채택된 답변
Paul
2024년 11월 24일
Can't recreate on Answers what you're seeing when using surface. However, I think you get what you're lookng for by using pcolor instead.
load by_sc1;load fby; load cfsby; load t1;
t = t1; cfsby = cfsby1; by_sc = bysc1; %?
figure
surface(t,fby,abs(cfsby)); shading flat;
%pcolor(t,fby,abs(cfsby)); shading flat;
set(gca,'YScale','log')
xlim([17+25./60 17+28./60]); ylim([0.02,1]);
colormap('jet');
caxis([0 0.05]);
set(gca,...
'YTick', [0.01 0.1 0.2 0.5 1 2 3 4 5], 'YTickLabel',[0.01 0.1 0.2 0.5 1 2 3 4 5]);
% Customize appearance
set(gca, 'XMinorTick', 'on', 'YMinorTick', 'on', 'FontSize', 18, 'fontweight', 'b');
set(gca, 'LineWidth', 2.25, 'TickLength', [0.010 0.010]);
% fo = (q .* B) / (2 * pi_value * m);
q = 1.602e-19; % Charge in Coulombs
mo = 2.657*1e-26;
mhe = 6.64*1e-27;
fo = (q .* by_sc * 1e-9) / (2*pi*mo);
fhe = (q .* by_sc * 1e-9) / (2*pi*mhe);
hold on;
% figure;
plot(t,fhe,'--w','LineWidth',5)
hold on;
plot(t,fo,'--w','LineWidth',2)
figure
pcolor(t,fby,abs(cfsby)); shading flat;
set(gca,'YScale','log')
xlim([17+25./60 17+28./60]); ylim([0.02,1]);
colormap('jet');
caxis([0 0.05]);
set(gca,...
'YTick', [0.01 0.1 0.2 0.5 1 2 3 4 5], 'YTickLabel',[0.01 0.1 0.2 0.5 1 2 3 4 5]);
% Customize appearance
set(gca, 'XMinorTick', 'on', 'YMinorTick', 'on', 'FontSize', 18, 'fontweight', 'b');
set(gca, 'LineWidth', 2.25, 'TickLength', [0.010 0.010]);
hold on;
% figure;
plot(t,fhe,'--w','LineWidth',5)
hold on;
plot(t,fo,'--w','LineWidth',2)
추가 답변 (1개)
Star Strider
2024년 11월 24일
편집: Star Strider
2024년 11월 25일
Plotting on the surface itself is straightforward. It simply requires using the scatteredInterpolant function to create and plot an appropriate ‘z’ value, and using plot3 to plot the lines.
Try this —
mats = dir('*.mat');
for k = 1:numel(mats)
load(mats(k).name)
% whos('-file', mats(k).name)
end
t = t1;
cfsby = cfsby1;
by_sc = bysc1;
% fby
% size(cfsby)
[FBY,T] = ndgrid(fby, t);
surface(t,fby,abs(cfsby)); shading flat;
set(gca,'YScale','log')
xlim([17+25./60 17+28./60]); ylim([0.02,1]);
colormap('jet');
caxis([0 0.05]);
set(gca,...
'YTick', [0.01 0.1 0.2 0.5 1 2 3 4 5], 'YTickLabel',[0.01 0.1 0.2 0.5 1 2 3 4 5]);
% Customize appearance
set(gca, 'XMinorTick', 'on', 'YMinorTick', 'on', 'FontSize', 18, 'fontweight', 'b');
set(gca, 'LineWidth', 2.25, 'TickLength', [0.010 0.010]);
% fo = (q .* B) / (2 * pi_value * m);
q = 1.602e-19; % Charge in Coulombs
mo = 2.657*1e-26;
mhe = 6.64*1e-27;
fo = (q .* by_sc * 1e-9) / (2*pi*mo);
fhe = (q .* by_sc * 1e-9) / (2*pi*mhe);
F = scatteredInterpolant(T(:),FBY(:),abs(cfsby(:))); % Create ‘scatteredInterpolant’ Interpolation Function
zfo = F(double(t),double(fo)); % Return ‘z’ Value
zfhe = F(double(t),double(fhe)); % Return ‘z’ Value
hold on;
% figure;
% plot(t,fhe,'--w','LineWidth',5)
plot3(t,fhe,zfhe,'--w','LineWidth',5)
hold on;
% plot(t,fo,'--w','LineWidth',2)
plot3(t,fo,zfo,'--w','LineWidth',2)
EDIT — (25 Nov 2024 at 02:58)
Showing the surface in 3D illustrates the effect —
figure
surface(t,fby,abs(cfsby)); shading flat;
set(gca,'YScale','log')
% xlim([17+25./60 17+28./60]); ylim([0.02,1]);
colormap('jet');
caxis([0 0.05]);
set(gca,...
'YTick', [0.01 0.1 0.2 0.5 1 2 3 4 5], 'YTickLabel',[0.01 0.1 0.2 0.5 1 2 3 4 5]);
% Customize appearance
set(gca, 'XMinorTick', 'on', 'YMinorTick', 'on', 'FontSize', 18, 'fontweight', 'b');
set(gca, 'LineWidth', 2.25, 'TickLength', [0.010 0.010]);
hold on
% plot(t,fhe,'--w','LineWidth',5)
plot3(t,fhe,zfhe,'--w','LineWidth',5)
% plot(t,fo,'--w','LineWidth',2)
plot3(t,fo,zfo,'--w','LineWidth',2)
view(135,30)
.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!