필터 지우기
필터 지우기

How can I add a second x-axis on top of the matlab figure for the same graph?

조회 수: 40 (최근 30일)
I have the following plot on matlab and want to add a second x-axis on top to show the corresponding distances with the same number of ticks and tick labels that can be found by:
distances (m) = (time_tau *10^-9) * 3*10^8
This is the plot:
% delay-spatial domain surf plot
figure
contourf( flip(time_tau), d_up, 20 .* log10(abs(zz_hts_tran_filtered_shift')), 'EdgeColor', 'none')
Unrecognized function or variable 'time_tau'.
set(gca, 'FontSize', 16)
set(gcf, 'color', 'white')
%set(gca, 'YDir', 'reverse')
ylabel('$$\Delta_{\mathrm{\phi}} ~(^\circ)$$', 'Interpreter', 'Latex')
xlabel('$$\tau ~\mathrm{(ns)}$$', 'Interpreter', 'Latex')
zlabel('$$\hat{\sigma}_{\mathrm{eff}}~\mathrm{dB/m^2}$$', 'Interpreter', 'Latex')
xlim([first_limit, last_limit]);
colormap('jet'); % Choose your preferred colormap
colorbar('eastoutside');
  댓글 수: 4
Dyuman Joshi
Dyuman Joshi 2023년 10월 30일
There's still an undefined variable.
Also, can you show what is the expected output/result?
load('time_tau.mat')
load('zz_hts_tran_filtered_shift.mat')
whos
Name Size Bytes Class Attributes ans 1x37 74 char cmdout 1x33 66 char time_tau 1x1594 12752 double zz_hts_tran_filtered_shift 1594x21 535584 double complex
% delay-spatial domain surf plot
figure
contourf( flip(time_tau), d_up, 20 .* log10(abs(zz_hts_tran_filtered_shift')), 'EdgeColor', 'none')
Unrecognized function or variable 'd_up'.
set(gca, 'FontSize', 16)
set(gcf, 'color', 'white')
%set(gca, 'YDir', 'reverse')
ylabel('$$\Delta_{\mathrm{\phi}} ~(^\circ)$$', 'Interpreter', 'Latex')
xlabel('$$\tau ~\mathrm{(ns)}$$', 'Interpreter', 'Latex')
zlabel('$$\hat{\sigma}_{\mathrm{eff}}~\mathrm{dB/m^2}$$', 'Interpreter', 'Latex')
xlim([first_limit, last_limit]);
colormap('jet'); % Choose your preferred colormap
colorbar('eastoutside');
demos serghiou
demos serghiou 2023년 10월 30일
Yes sorry, here is the rest of the variables and output figure.
first_limit = t_total(1) - 1.5;
last_limit = t_total(end) + 2.5;

댓글을 달려면 로그인하십시오.

채택된 답변

Voss
Voss 2023년 10월 30일
This creates text objects above the axes at the locations of the x-tick marks for the new x-tick labels, and another text object for the new x-label.
% random data:
time_tau = 1:100;
d_up = 1:10;
zz_hts_tran_filtered_shift = randn(100,10);
first_limit = 20;
last_limit = 65;
% delay-spatial domain surf plot
figure()
contourf( flip(time_tau), d_up, 20 .* log10(abs(zz_hts_tran_filtered_shift')), 'EdgeColor', 'none')
set(gca, 'FontSize', 16)
set(gcf, 'color', 'white')
%set(gca, 'YDir', 'reverse')
ylabel('$$\Delta_{\mathrm{\phi}} ~(^\circ)$$', 'Interpreter', 'Latex')
xlabel('$$\tau ~\mathrm{(ns)}$$', 'Interpreter', 'Latex')
zlabel('$$\hat{\sigma}_{\mathrm{eff}}~\mathrm{dB/m^2}$$', 'Interpreter', 'Latex')
xlim([first_limit, last_limit]);
colormap('jet'); % Choose your preferred colormap
colorbar('eastoutside');
% store some needed things:
ax = gca();
yl = ylim();
xt = xticks();
fs = get(ax,'FontSize');
% decrease the axes height a little, to make room for the new "xlabel"
ax.Position(4) = 0.93*ax.Position(4);
% create tick labels at the top of the plot:
text(xt,yl(2)*ones(numel(xt),1),string((xt *10^-9) * 3*10^8), ...
'VerticalAlignment','bottom', ...
'HorizontalAlignment','center', ...
'FontSize',fs)
% create a new "xlabel":
text(mean(xlim()),yl(2)+0.08*(yl(2)-yl(1)),'distances (m)', ...
'VerticalAlignment','bottom', ...
'HorizontalAlignment','center', ...
'FontSize',fs)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by