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

2 ビュー (過去 30 日間)
megha
megha 2024 年 11 月 24 日
編集済み: Star Strider 2024 年 11 月 25 日
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
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.
megha
megha 2024 年 11 月 24 日
thanks! data attached. Please make minor adjustment in the codes as needed.

サインインしてコメントする。

採用された回答

Paul
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 件のコメント
megha
megha 2024 年 11 月 24 日
Wohoo! Thanks @Paul! That worked!
Thanks for saving my time and your valuable efforts

サインインしてコメントする。

その他の回答 (1 件)

Star Strider
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)
.

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by