Search code examples
matlabplotmatlab-figuremeshfigure

Matlab: `mesh()` plot with less number of grid


Let's say data is a matrix of size 129 * 129.

by using

mesh(data, 'FaceColor', 'none', 'EdgeColor', 'black')

we get something like

enter image description here

We can find that the grid are quite intense. I would like to have the same figure but with less number of mesh lines, something like

enter image description here


It is of course doable to plot a smaller data, for example data(1:10:end, 1:10:end). But in this way, the plot are not accurate as before anymore.

Another example is plot(..., 'MarkerIndices', ...). This can give you a plot with less number of markers without modifying the plot. https://www.mathworks.com/help/matlab/creating_plots/create-line-plot-with-markers.html


Solution

  • An alternative approach is to use plot3 to plot the mesh lines manually. That way you can plot each line smoothly using all the data points, but not have as many lines.

    [X,Y,Z] = peaks(201);
    step = 5;
    
    plot3(X(:,1:step:end),Y(:,1:step:end),Z(:,1:step:end),'k')
    hold on
    plot3(X(1:step:end,:).',Y(1:step:end,:).',Z(1:step:end,:).','k')
    hold off
    

    enter image description here