File Exchange Pick of the Week

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’)

Video Content

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).


Bob, Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

  • oleg: The author has implemented skewness, kurtosis and checks answering appropriately to the critic.
  • Ashok: how to store 10 or more random number in a loop a loop for i = 1:n mean(i) = input(’enter the mean value...
  • Ben: Doug, Thanks for the very helpful videos! Uitables seem like a convenient way to make a customized property...
  • oleg: Allstats has no checks, no comments and could also be improved (talking about prctile implementatio). Not to...
  • Todd: Additional information and a link to download free MATLAB and Simulink LEGO MINDSTORMS NXT code can be found at...
  • Doug: @Leo, Here is the “English version” of that code. “vec = []” makes an empty variable...
  • leo: Dear Doug I have a question in your code ‘October 9th, 2009 at 13:53′ vec = []; vec = [vec val]; I...
  • Shanker Keshavdas: You sir, are a gentleman and a scholar… No really, helped me out a lot. As to what is...
  • Quan Zheng: how can I get a copy of stepspecs.m?
  • Doug: @Lucy I think this is what you seek to move a line with the mouse in MATLAB. http://blogs.math...

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