Color a sphere surface/polar plot axis-wise

조회 수: 19(최근 30일)
Jon Legarreta
Jon Legarreta 2016년 5월 12일
댓글: Jon Legarreta 2016년 5월 12일
Hi there,
I would like to produce both a sphere and a polar plot whose surface color is defined at each XYZ axis as follows:
Top-bottom (Z) = blue
Left-right (Y) = red
Anterior-posterior (X) = green
The color in the boundaries/interfaces should be an interpolation of them.
Such as here:
and here (for the polar plot):
I have been googling for a while but did not find much help to do it.
PS: Similar questions seem to have been asked previously with a few variants, but the answers given seem not reproduce the figures pointed above.


Mike Garrity
Mike Garrity 2016년 5월 12일
Something like this, perhaps?
[x,y,z] = sphere(40);
col(:,:,1) = abs(y);
col(:,:,2) = abs(x);
col(:,:,3) = abs(z);
axis equal
Here's a start on the "polar" one, but I'll let you add the grid & text.
axis off
set(gca,'CameraUpVector',[1 0 0])
  댓글 수: 1
Jon Legarreta
Jon Legarreta 2016년 5월 12일
Hi Mike,
thanks for your answer. Helps a lot !
I successfully added the sticks and the text to the sphere using
[X,Y,Z] = cylinder(cylinderRadius, cylinderResolution);
Z(2,:) = -(Z(1,:) + cylinderLength/2);
Z(1,:) = Z(1,:) + cylinderLength/2;
siStick = mesh(X,Y,Z,'FaceColor','b','EdgeColor','none');
yRotAx = [0 1 0]; % rotation around y-axis
rotate(lrStick, xRotAx, angle);
text(siStick.XData(1,1),siStick.YData(1,1),siStick.ZData(1,1) + offset,'S',...
Although it does not seem the easiest way, I did not find the way to do it thorough simpler transformations/functions.
As for the disc, I am having a hard time trying to mimic the way I set the text for the sphere case, and I am not succeeding.
Did not attempt the grid.
Any hints?

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by