How can I add a second x-axis on top of the matlab figure for the same graph?
조회 수: 70 (최근 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')
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
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
% 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');
채택된 답변
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 Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!