Legend in plot of data points
    9 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    sna hsn
 am 30 Apr. 2023
  
    
    
    
    
    Bearbeitet: Adam Danz
    
      
 am 30 Apr. 2023
            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 Kommentare
Akzeptierte Antwort
  albara
      
 am 30 Apr. 2023
        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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Legend finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



