Shift the z -value of contour plot in Matlab 2014b

前端 未结 3 1215
花落未央
花落未央 2021-01-23 11:28

I\'m trying to make a figure of a surface plot, and beneath the surface I wish to show the contour lines, but I want the contour to be at z = -1 instead of at the d

相关标签:
3条回答
  • 2021-01-23 12:16

    So, I couldn't really figure out to do it as proposed in the example I found and posted, but I found a way that works. What I ended up doing was basically this:

    figure
    hold on
    surf(X,Y,Z+1);
    contour(X,Y,Z);
    zz = get(gca,'ZTick');
    set(gca,'ZTickLabel',sprintf('%3.1f\n',zz-1));
    

    This gets me the surf and contour in the same figure, but yields some problems with color mappings.

    0 讨论(0)
  • 2021-01-23 12:27

    I got the same problem. And finally, I got the contourf on plane Z=-10. My MATLAB version is

    MATLAB Version: 8.5.0.197613 (R2015a)

    hope the codes work 4 you

    clear all
    clc
    
    [X,Y,Z] = peaks;
    
    [~,hContour] = contourf(X,Y,Z,20,'edgecolor','none');
    
    hContour.ContourZLevel = -10; % set the contour's Z position
    
    view(44,30)
    
    colormap(jet)
    
    0 讨论(0)
  • 2021-01-23 12:29

    I figured out how to solve the problem with color mappings the user Kine faced. Note: I've done the following code on MATLAB R2015b:

    offset = 0.5;
    plotHandle = surfc(X1, Y1, Z1);
    hold on;
    % This line moves the surface up from its original location and increases the space between the surface and the contour plot
    plotHandle(1).ZData = plotHandle.ZData + offset;
    % However in doing so the color mappings are changed. So, the line below restores these mappings
    plotHandle(1).CData = plotHandle.CData - offset;
    
    % This line changes fills the contour plot
    plotHandle(2).Fill = 'on';
    grid on;
    
    % The following lines draw critical areas on the contour line, as it was more readable in my case
    axisHandle = gca;
    ZHeight = axisHandle.ZLim(1);
    plot3(X2, Y2, ZHeight, 'o', 'MarkerSize', 10, 'LineWidth', 1, 'Color', 'k', 'MarkerFaceColor', 'm');
    plot3(Y2, X2, ZHeight, 'o', 'MarkerSize', 10, 'LineWidth', 1, 'Color', 'k', 'MarkerFaceColor', 'm');
    
    hold off
    
    0 讨论(0)
提交回复
热议问题