Contourf and NaNs (how to make white regions transparent)

前端 未结 2 1511
半阙折子戏
半阙折子戏 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

提交回复
热议问题