Why do I get a different result from ISOSURFACE when it plots to a subplot?

2 views (last 30 days)
Graphics produced by the ISOSURFACE function differ when drawing to a subplot compared to executing the same code in a figure without subplots, as the following example shows:
[x y z]=meshgrid(-2:.2:2, -2:.2:2, -2:.2:2);
v = x.*exp(-x.^2-y.^2-z.^2);
figure(1)
isosurface(x,y,z,v,0.3)
figure(2)
subplot(221)
isosurface(x,y,z,v,0.3)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This is the expected behavior. The SUBPLOT function does not merely "partition" the figure into four areas; rather, it partitions the figure into four areas and creates an axis object within one of those areas. Therefore, the ISOSURFACE command that executes after the call to SUBPLOT is plotting into an preexisting 2-D axis.
Consider this code:
[x y z]=meshgrid(-2:.2:2, -2:.2:2, -2:.2:2);
v = x.*exp(-x.^2-y.^2-z.^2);
figure(3);
gca;
isosurface(x,y,z,v,0.3);
This code behaves correctly; it
- Creates a figure
- Creates an axis (2D)
- Plots the isosurface into it as 2-D and with no lighting, since the axis aready existed.
On the other hand, executing this:
[x y z]=meshgrid(-2:.2:2, -2:.2:2, -2:.2:2);
v = x.*exp(-x.^2-y.^2-z.^2);
figure(1);
isosurface(x,y,z,v,0.3);
Will result in a 3-D ISOSURFACE, because the call to ISOSURFACE is creating an axes with the appropriate lighting and shading. The documentation for ISOSURFACE states:
"Special Case Behavior -- isosurface Called with No Output Arguments
If there is no current axes and you call isosurface with without assigning output arguments, MATLAB creates a new axes, sets it to a 3-D view, and adds lighting to the isosurface graph. "
This is why the "no previously existing axis" cases looks as expected and the SUBPLOT case does not.
To work around this issue, you can manually set the appropriate properties using the following commands.
view(3)
camlight
lighting gouraud

More Answers (0)

Products


Release

R2006a

Community Treasure Hunt

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

Start Hunting!