Legend in plot of data points
조회 수: 14 (최근 30일)
이전 댓글 표시
Hello everyone
I have some nodes that plot them as a 3D Plot as below:
p1=[6 3 0]';
p2=[3 5 0]';
p3=[1 7 0]';
p4=[1 -1 0]';
x=[];
y=[];
z=[];
x(1)=p1(1), y(1)=p1(2), z(1)=p1(3);
x(2)=p2(1), y(2)=p2(2), z(2)=p2(3);
x(3)=p3(1), y(3)=p3(2), z(3)=p3(3);
x(4)=p4(1), y(4)=p4(2), z(4)=p4(3);
figure
p1=plot3(x,y,z,'rd','MarkerFaceColor','b')
grid on
xlim([-5 10])
ylim([-5 10])
zlim([-5 10])
xlabel('X Axis'), ylabel('Y Axis'), zlabel('Z Axis');
Now, I want to shape p1 as star (*) (I think it is MarkerShape but I don't know how do it for one point)
and use legend only for one point (p1) because p1 is different from others.
Thank you
댓글 수: 0
채택된 답변
albara
2023년 4월 30일
p1 as a star, you can use the 'Marker' property with the value '*'. To create a legend only for the first point, you can provide a label to the 'DisplayName' property. Here's the updated code:
p1 = [6 3 0]';
p2 = [3 5 0]';
p3 = [1 7 0]';
p4 = [1 -1 0]';
x = [];
y = [];
z = [];
x(1) = p1(1), y(1) = p1(2), z(1) = p1(3);
x(2) = p2(1), y(2) = p2(2), z(2) = p2(3);
x(3) = p3(1), y(3) = p3(2), z(3) = p3(3);
x(4) = p4(1), y(4) = p4(2), z(4) = p4(3);
figure
% Plot the first point with a star marker
p1 = plot3(x(1), y(1), z(1), 'r*', 'MarkerFaceColor', 'b', 'DisplayName', 'p1');
hold on
% Plot the remaining points with a diamond marker
p_rest = plot3(x(2:end), y(2:end), z(2:end), 'rd', 'MarkerFaceColor', 'b');
grid on
xlim([-5 10])
ylim([-5 10])
zlim([-5 10])
xlabel('X Axis'), ylabel('Y Axis'), zlabel('Z Axis');
% Create a legend only for the first point
legend(p1);
This code will plot the first point (p1) with a star marker and the other points with a diamond marker. The legend will only display the label for p1.
Important: There may be some mistakes in this answer Experts can tell if there are any mistakes and you might find better answer
Give me your feedback
Thanks
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!