简体   繁体   中英

Add text from vectors at points in 3D graph

I would like to add text at the data points in my 3D plot. I want the contents of my xx , yy and zz vectors to be the text of their corresponding points.

xx = [124 87];
yy = [50 37];
zz = 1.0e-2*[0.4170 0.3163];
[x,y]=meshgrid(0:150,0:60);
z=zeros(size(x));
z(sub2ind(size(z),yy,xx))=zz;
surf(x,y,z)

Below was my attempt to add the text in a loop so they can be displayed on the graph at the correct point.

str = {};
for i=1:size(xx)
    str{i} = strcat( num2str(xx(i)), num2str(yy(i)), num2str(zz(i)) ); 
end
text(xx,yy,zz,str)

I would like my graph to display the text somewhat similar to the image below. The graph below is the correct graph as well.

在此输入图像描述

Instead of strcat, str should be a nested cell array.

The following code will work.

str = cell(size(xx, 2), 1);
for i=1:size(xx, 2)
    str{i} = {num2str(xx(i)), num2str(yy(i)), num2str(zz(i))}; 
end
text(xx, yy, zz,str)

在此输入图像描述

For adding 'x:', 'y:' and 'z:' to the label and showing it with offset (10%), I would do this.

str = cell(size(xx, 2), 1);
for i=1:size(xx, 2)
    str{i} = {['x: ' num2str(xx(i))], ['y: ' num2str(yy(i))], ['z: ' num2str(zz(i))]}; 
end
text(xx+0.1*xx, yy+0.1*yy, zz,str)

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM