Doug’s MATLAB Video Tutorials

August 13th, 2008

MATLAB Basics: Setting edge color for large surface plots

Often if you make a surface plot with SURF for a large dataset, it will appear all black because MATLAB is trying to draw all the edge lines. You can stop these lines from obscuring your data by turning the edge color off: a= peaks(1000); h = surf(a) set(h, 'edgecolor','none')

2 Responses to “MATLAB Basics: Setting edge color for large surface plots”

  1. Petr Pošík replied on :

    Hi Doug.

    Personally I tend to use the

    shading flat, shading interp, shading faceted

    commands. They take care of greater number of objects automatically, but internally use similar commands you presented in the video.

    Regards, Petr

  2. Matt Fig replied on :

    I often want the high shape resolution given by large data sets for a surface, but also want to see the net over the surface. This is useful for publication/presentation purposes. Since, as you show, using the net as is will make the whole surface black, I modify it by doing something like this:

     
    a = peaks(1000);
    opengl software
    h = surf(a);
    set(h, 'edgecolor','none')
    hold on
    x = 1:1000;
    k = [1 0:20:1000];  % The values to keep.
    k(2) = [];
    st = setxor(x,k);
    x(st) = NaN;  % Set most values so they won't plot.
    [xx,yy] = meshgrid(x);
    idx1 = isnan(xx)|isnan(yy);
    a(idx1) = NaN;
    idx2 = ~isnan(xx)&~isnan(yy);
    xx = reshape(xx(idx2),51,51);  % Reshape these guys.
    yy = reshape(yy(idx2),51,51);
    aa = reshape(a(idx2),51,51);
    m = mesh(xx,yy,aa+.04);  % Create the net.
    set(m,'edgecolor','black','facealpha',0,'linewidth',1)
    set(1,'units','normalized','position',[.05 .05 .85 .85])
     

    Note that I added a small value to the aa matrix. This is because if left alone the net will have patches that are blocked by the surface, mainly at the peaks. Of course it makes the underside of the surface look worse in this regard, but as I said, I use this technique to get a static image for publication/presentation purposes.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

Doug's picture

These postings are the author's and don't necessarily represent the opinions of The MathWorks.