1
votes

MWE below

I'm plotting an energy surface using Matlabs surf function. I first create my data points at various azimuthal and elevation angles, and next I convert these to an (x,y,z)-coordinate using the usual spherical-to-cartesian equations, and reshape the coordinates into a matrix.

However, when I plot this, I find that all data points are represented as the lower left corner of a "patch" of color, instead of centrally in the patch of color.

However, when I am scaling the radius of the surface to reflect the energy at that point, any dimples in the surface has all messed up colors due to this effect, i.e. any symmetry of the data is lost in the visualization. I would like this dimple to have roughly symmetrical color around the deepest point here.

The example shown is with the conversion from spherical to cartesian coordinates shifted by half the angular difference between two data points - this means that patches are centered around the right spot, but the coloring is still off.

Is there a way to "center" the colored patches on the exact direction that the data was taken?

scaling = 100;
min_val = 0.5

count = 1;
azstep = 10;
elstep = 10;

az = 0:azstep:360;
el = -90:elstep:90;
for ii = 1:length(az)
    for jj = 1:length(el)
        if any(az(ii) == [260 270 280]) && any(el(jj) == [-10 0 10])
            r_output(count) = 0.8;
        else
            r_output(count) = 1;
        end
        c(count) = r_output(count);
        r(count) = 1 + scaling.*(r_output(count)/min_val) - scaling;
        x(count) = (r(count)) .* cosd(el(jj)) .* cosd(az(ii));
        y(count) = (r(count)) .* cosd(el(jj)) .* sind(az(ii));
        z(count) = (r(count)) .* sind(el(jj));
        count = count + 1;
    end
end

X = reshape(x,length(el),length(az));
Y = reshape(y,length(el),length(az));
Z = reshape(z,length(el),length(az));
C = reshape(c,length(el),length(az));

figure
hold on

surf(X,Y,Z,C)
colorbar
axis equal
xlabel('X axis'); ylabel('Y axis'); zlabel('Z axis');

Result from code above

1

1 Answers

0
votes

Change the shading!

Adding shading interp in the end of your code produces the following image:

enter image description here

if you want the lines, then change the surf call to:

h=surf(X,Y,Z,C)
colorbar
shading interp
set(h','edgecolor','k')

as shading will remove them.

enter image description here

Note that you still get some artefacts in some corners. They seem to be generated by floating point errors when interpolating, so the only way of improving them seems to be just making a more densely populated sphere.