File Exchange

image thumbnail


version (3.91 KB) by Michelle Hirsch
Add a shadow to an existing surface plot.


Updated 17 Aug 2015

From GitHub

View Version History

View license on GitHub

Editor's Note: This file was a File Exchange Pick of the Week

SHADOWPLOT Add a shadow to an existing surface plot

For some surface plots, it can be helpful to visualize the shadow (2D projection) of the surface. This can give a quick perspective on the data's variance.

SHADOWPLOT PLANE Adds a shadow plot on the PLANE boundary
PLANE can be:
x, y, or z: Plots on back/top wall of x, y or z
1 .. 6 : Plots on Nth wall, numbered as in AXIS:
[xmin xmax ymin ymax zmin zmax]

SHADOWPLOT(HAX,PLANE) Adds a shadow plot on the Nth wall on axes HAX
HS = SHADOWPLOT(...) Returns a handle to the shadow (a patch)

shading interp
shadowplot x % Back X Wall
shadowplot y % Back Y Wall

Cite As

Michelle Hirsch (2021). SHADOWPLOT (, GitHub. Retrieved .

Comments and Ratings (12)

Andrea Libri


it is a really useful m file to create a projection!


For surf(x,y,peaks)

if peaks is size n x m
then x must be size 1 x m
and y must be size n x 1


Actually I realized I can just pass in a patch/surface object and adjust the kids/kisp loops or get rid of them completely to only shadow a single object. Works like a charm!


Great function! Is there any way to shadow only 1 object though (say a particular patch handle only) as opposed to all surface/patch objects on an axis?


Frederick Bryan

I repeat Usman's request. Is there any way to add projections of lines/points too? (e.g., using plot3/line/quiver)

Usman Ali

hi, can we use shadow plot of plot3(), i am trying to do so but no successful. it only works with mesh/surf plots. help

Pavel Mazniker

Joseph Kirk

line 79: if length(axis==4)

I don't think this achieves the intended purpose. (axis==4) will evaluate to a logical array of either 4 or 6 elements. length(axis==4) will thus equal 4 or 6, so the if-statement will always execute.

It should be: if length(ax)==4
This will execute the if-statement if the axis view is 2D, but not if the view is already 3D.


Works well. Found a coding error: change line 120 to "surfdata{2} = repmat(surfdata{2}',1,Nx);"

John D'Errico

Its former self is only a "shadow" of what it is now. Sorry. I had to say it. 8-)

John D'Errico

I liked the idea until I tried it out. Shadowplot is of limited use in its current form. It works very nicely on the output of peaks, so then I tried it on one of my own 3d plots. It fails on more general patch objects, able to work on only objects of type 'surface'.

MATLAB Release Compatibility
Created with R14SP1
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!