MATLAB: Plotting/Saving X-Y views of mesh function in subplots

狂风中的少年 提交于 2019-11-30 16:41:17

Here is a stripped example very similar to what you are trying to achieve:

%# create axes, and set the view of each
hAx(1) = subplot(221); h = mesh(peaks);   view(3)
hAx(2) = subplot(222); copyobj(h,hAx(2)); view(0,90), title('X-Y')
hAx(3) = subplot(223); copyobj(h,hAx(3)); view(0,0) , title('X-Z')
hAx(4) = subplot(224); copyobj(h,hAx(4)); view(90,0), title('Y-Z')

%# set properties of axes
for i=1:4
    grid(hAx(i), 'on')
    axis(hAx(i), 'tight')
    xlabel(hAx(i), 'Delay (sec)');
    ylabel(hAx(i), 'Doppler (Hz)');
    zlabel(hAx(i), 'Ambiguity function');
end
title(hAx(1), 'Short Tone Ping z(\tau;F_d)')
hc = colorbar('Peer',hAx(1));
set(get(hc,'YLabel'), 'String','Magnitude-Squared (dB)')

When you call axes1 = axes(); right below subplot(2,1,1);, you are setting axes1 to the default full-window axis when you call axes() without any arguments, which is causing the overlap. Instead, try using the handle returned by subplot to generate the axes handle. Try the following code for the second section:

%Ambiguity Slices
fid = figure(fnum);
    H1 = subplot(2,1,1);
        pos1 = get(H1, 'Position');
        set(H1,'Position',[pos1(1) pos1(2) 0.8*pos1(3) pos1(4)]); %leave space for colorbar;
        grid on;
        msh = mesh(taux,fdy,z);
        view([90 0]);
        mapping = caxis;
        xlabel ('Delay - seconds','Visible','off');
        ylabel ('Doppler - Hz');
        zlabel ('Ambiguity function (Normalized Magnitude-Squared)','Visible','off');
        fname = strcat(name,' (Ambiguity Function Slice z(\tau;F_d) @ \tau = 128)');
        title(fname)
    H2 = subplot(2,1,2);
        pos2 = get(H2, 'Position');
        set(H2,'Position',[pos2(1) pos2(2) 0.8*pos2(3) pos2(4)]); %leave space for colorbar;
        grid on;
        msh = mesh(taux,fdy,z);
        caxis(mapping);
        view([0 0]);
        xlabel ('Delay - seconds','Visible','off');
        ylabel ('Doppler - Hz','Visible','off');
        zlabel ('Ambiguity function (Normalized Magnitude-Squared)','Visible','off');
    axes('Position', [0.05 0.05 0.9 0.9], 'Visible', 'off'); %setup axes for colorbar;
    caxis(mapping);
    cb = colorbar();
    ylabel(cb, 'Magnitude-Squared');
    fname = strcat(name,' (Ambiguity Function Slice z(\tau;F_d) @ F_d = 0)');
    title(fname)
    printFig(fid,fnum,slname)
    fnum = fnum+1;

This (should) at least get everything displayed how you want - I believe that the colorbar scale will not correspond to anything in particular (most likely the number of discrete colors in the bar), so extra code is needed to make sure both plots use the same colormap, and that you change the colormap for the colorbar.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!