Shading with plot3

조회 수: 23 (최근 30일)
Niklas
Niklas 2016년 5월 26일
답변: Walter Roberson 2016년 5월 26일
If you have plotted several dots with plot3(x,y,z) is it possible to add some shading because, shading interp, does not work. Something like how far away the dots are from origo?

답변 (1개)

Walter Roberson
Walter Roberson 2016년 5월 26일
Instead of using plot3() you can use
r = sqrt(x.^2 + y.^2 + z.^2);
g = patch('Vertices', [x(:), y(:),z(:); nan nan nan], 'Faces', (1:length(x)+1).', 'FaceVertexCData', [r(:); nan], 'EdgeColor', 'interp', 'Marker','*')
This will shade both the lines and the markers.
There is a "trick" here, which is to put in the nan as a face. If you do not put in the nan (or inf instead) then patch() will close the polygon.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by