shading — Set surface shading to flat, interpolated, or faceted modes with MATLAB-compatible shading syntax.
shading controls how surface-family plots render color interpolation and facet edges. It supports MATLAB-compatible forms such as shading flat, shading interp, and shading faceted for surf/mesh workflows.
Syntax
ok = shading(mode)Inputs
mode- Type
StringScalar- Required
- Yes
- Description
- Shading mode token: 'flat'|'interp'|'faceted'.
Returns
ok- Type
LogicalArray- Description
- True on successful shading mode update.
Errors
RunMat:shading:InvalidArgument- When
- Shading mode is missing, non-string, or unsupported.
- Message
shading: invalid argument
RunMat:shading:TooManyOutputs- When
- More than one output is requested.
- Message
shading: at most one output is supported
Behavior
shading flat uses flat shading across faces.
shading interp enables interpolated/smooth shading across the rendered surface.
shading faceted restores faceted surface presentation.
The command changes existing surface-family objects on the current axes only; it does not set a default for future surfaces or modify unrelated subplots.
An assigned logical state/success result is a RunMat extension. MATLAB compatibility mode allows command calls but rejects an explicitly requested result before changing state.
Placement and display
These commands update shared graphics state and may notify figure observers. Numeric array acceleration remains with the original plotting/rendering pipeline; the commands do not launch array-provider kernels. Graphics display requires a browser graphics host or a desktop graphics host.
Control arguments must already be host values. Unsupported resident controls reject without provider downloads; existing resident plot buffers stay owned by their plotting/rendering paths. Invalid syntax and excess output requests are checked before creating or changing graphics state.
Examples
Apply interpolated shading to a surface
[X,Y] = meshgrid(linspace(-3,3,50)); Z = sin(X).*cos(Y); h = surf(X,Y,Z); shading interp;Compare flat and faceted shading across subplots
[X,Y] = meshgrid(linspace(-3,3,40)); Z = sin(X).*cos(Y);
subplot(1,2,1); h1 = surf(X,Y,Z); shading flat;
subplot(1,2,2); h2 = surf(X,Y,Z); shading faceted;Using shading with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how shading changes the result.
Run a small shading example, explain the result, then change one input and compare the output.
FAQ
What's the difference between interp, flat, and faceted shading?⌄
flat fills each face with a single color (the value at one vertex). interp smoothly interpolates color across each face, producing a continuous gradient. faceted is like flat but with visible black edge lines between faces — this is the default surf appearance.
When should I use shading interp vs faceted?⌄
Use interp when you want a smooth, publication-quality surface without visible grid edges — good for dense meshes or photorealistic renders. Use faceted (the default) when you want to see the mesh structure, which helps during debugging or when the grid resolution matters to the reader.
Does shading affect mesh plots or just surf?⌄
It updates existing surface-backed objects created by surf and mesh, including the surface component of supported composite plots such as surfc and meshc. It does not change independent patch objects or set a default for future objects. Edge visibility also depends on the surface's wireframe and edge settings.
Related Plotting functions
2D Charts
area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem
Other
addpoints · ancestor · animatedline · autumn · axes · barh · bone · caxis · cla · clf · clim · colorcube · colororder · cool · copper · copyobj · cylinder · daspect · datacursormode · dataTipTextRow · drawnow · fcontour · figure · fill · fill3 · findobj · fsurf · gobjects · gray · groot · hgload · hgsave · hidden · histogram2 · hold · hot · inferno · isgraphics · ishandle · jet · line · lines · linkaxes · magma · openfig · opengl · pan · parula · patch · pink · plasma · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · sphere · spring · stackedplot · subtitle · summer · suptitle · text · textscatter · textscatter3 · triplot · turbo · viridis · waitbar · winter · wordcloud · xlabel · xlim · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · ylabel · ylim · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zlim · zoom
More plotting resources
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.