why am I Unable to overplot a line on a surface plot?

26 views (last 30 days)
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 Comments
Paul
Paul on 24 Nov 2024 at 20:45
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.
megha
megha on 24 Nov 2024 at 21:05
thanks! data attached. Please make minor adjustment in the codes as needed.

Sign in to comment.

Accepted Answer

Paul
Paul on 24 Nov 2024 at 21:21
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 Comment
megha
megha on 24 Nov 2024 at 21:25
Wohoo! Thanks @Paul! That worked!
Thanks for saving my time and your valuable efforts

Sign in to comment.

More Answers (1)

Star Strider
Star Strider on 24 Nov 2024 at 22:47
Edited: Star Strider on 25 Nov 2024 at 2:58
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)
.

Community Treasure Hunt

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

Start Hunting!