One surface is changing the color of another

4 views (last 30 days)
I have a program that, without going into needless detail, plots the potential energy wells of several regions around the surface of a sphere. The simplified code looks a bit like:
for i=1:n
% spend a few lines calculating the potential, P, in the region with coordinates
% (az,el) which surrounds point i
[x,y,z] = sph2cart(az, el, P)
surf(x,y,z,P)
end
%draw the sphere so a reference height can be gauged:
[x,y,z] = sphere
surf(x,y,z, 'FaceColor',[0.7 0.7 0.7])
What's weird is that the potential wells are showing up as monochromatic. Pausing the code in the debugger after each surface is drawn, I noticed that each successive surface is changing the colors of all the previous ones, with the sphere causing the most dramatic change. My guess is that there is some sort of global color map for all surfaces on a set of axes, but I can't find a way to turn that off.
Thanks in advance!
  1 Comment
Image Analyst
Image Analyst on 26 Aug 2023
You forgot to attach a screenshot to help us visualize it. Is it something like a golf ball and you want the surface to be one color and the dimples to be other colors (depending on the depth of the dimple at each location)?

Sign in to comment.

Accepted Answer

DGM
DGM on 26 Aug 2023
Moved: DGM on 26 Aug 2023
Without knowing the specifics, my guess is that there is fairly significant z-difference between the ranges of values represented by each surf plot.
All of the objects in a given axes share the same colormap and clim/caxis settings. When you add a new surf plot to the axes, it will update the current setting for clim to suit the range of the newest plot.
Even though you're explicitly setting a flat face color for the sphere surf, it still updates clim, and thus it can still affect the way all the other surfaces are colormapped (depending on the relative range of values).
I suggest looking at clim() and picking some fixed limits based on the overall range of the data that needs to be colormapped.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!