Contourf and NaNs (how to make white regions transparent)

前端 未结 2 1513
半阙折子戏
半阙折子戏 2021-02-19 16:19

I\'m trying to make a contourf plot but certain areas of the data array have NaNs (only in the data matrix, the x and y meshgrid matrices are full). I\'d like these

相关标签:
2条回答
  • 2021-02-19 16:41

    Building on H. Muster's answer, I've artificially created the bands by segmenting the data (you could use a simple function to choose the bands, or create them with contour on a dummy figure, return them, and re-use them).

    [X Y] = meshgrid(10:0.1:50);
    Z = X.*Y;
    Z(100:300,100:300) = NaN;
    figure
    hold on;
    h = pcolor(X,Y,round(Z/500)*500);
    set(h,'Edgecolor',  'interp');
    colormap jet;
    set(gca, 'XLim', [0 60], 'YLim', [0 60]);
    

    I'm afraid I don't have the toolbox that includes imread so can't show the underlying gradient, but I think this would work. I've had to increase the resolution by a factor of 10 to get a reasonably smooth image.

    enter image description here

    0 讨论(0)
  • 2021-02-19 16:51

    Would it be an option to use pcolor instead of contourf?

    [X Y] = meshgrid(10:50);
    Z = X.*Y;
    Z(10:30,10:30) = NaN;
    figure
    imshow(uint8(repmat(1:4:240,[60,1,3])));
    hold on;
    h = pcolor(X,Y,Z)
    set(h,'Edgecolor',  'interp');
    colormap jet;
    

    enter image description here

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