How to overlay a pcolor plot with a contour plot that uses a different colormap?

前端 未结 1 1574
生来不讨喜
生来不讨喜 2021-01-12 10:54

Minimum example that does not achieve it:

[X,Y,Z] = peaks;
figure;
pcolor(X,Y,Z);
shading flat;
hold all;
axes;
contour(X,Y,Z);
colormap gray;  % this should         


        
相关标签:
1条回答
  • 2021-01-12 11:31

    You can fix the problem by catenating two colormaps, and making sure that the values of the functions are such that they access the right part of the colormap:

    cm = [jet(64);gray(64)];
    figure,
    pcolor(X,Y,Z)
    shading flat
    hold on
    %# Z in the contour starts after the maximum
    %# of Z in pcolor
    contour(X,Y,Z-min(Z(:))+max(Z(:))+2,'LineWidth',2)
    %# apply the colormap
    colormap(cm)
    

    enter image description here

    For a more convenient solution, you may also want to have a look at this file exchange pick of the week

    0 讨论(0)
提交回复
热议问题