Probing a plot based on colormap information

How can I probe a plot with colormap data?
As you see, in this case, it only shows the xyz coordinates which is not really useful. I want to be able to see the colormap value (between 0 and 1).
Any ideas? I am using the trisurf function.

 채택된 답변

Simon Chan
Simon Chan 2022년 3월 11일
Try function datatip & dataTipTextRow if your MATLAB version is after 2019b.
[x,y] = meshgrid(1:15,1:15);
z = peaks(15);
T = delaunay(x,y);
s = trisurf(T,x,y,z);
dt = datatip(s);
s.DataTipTemplate.DataTipRows(end+1) = dataTipTextRow('Colormap Value',T,'%.1f');

댓글 수: 9

Thanks, but I get the following error:
Error using matlab.graphics.datatip.DataTipTemplate/set.DataTipRows
Value must be compatible with the data source.
In my code, "flow12" has the same dimensions as F. I think (?) this is the problem. Basically I have a value assigned to each face, rather than each vertex.
s = trisurf(F,P(:,1),P(:,2),P(:,3), flow12, 'Parent', app.UIAxes2_10);
c = colorbar(app.UIAxes2_10);
caxis(app.UIAxes2_10,[0.333 1]);
colormap(app.UIAxes2_10, jet);
c.Label.String = 'T11 Tensor';
dt = datatip (s);
s.DataTipTemplate.DataTipRows (end+1) = dataTipTextRow ('T11', flow12,'%.1f');
Try the following:
s.DataTipTemplate.DataTipRows (end+1) = dataTipTextRow ('T11', s.CData,'%.3f');
Same error unfortunately. :(
Could you please try once more.
clear; clc;
[x,y] = meshgrid(1:15,1:15);
z = peaks(15);
T = delaunay(x,y);
C = rand(size(T,1),1); % Color based on number of faces
s = trisurf(T,x,y,z,C);
axis equal;
c = colorbar;
caxis([0.333 1]);
colormap(jet);
c.Label.String = 'T11 Tensor';
dt = datatip(s);
s.DataTipTemplate.DataTipRows(end+1) = dataTipTextRow('Colormap Value',repmat(s.CData,1,3),'%.3f');
Mainly this one:
s.DataTipTemplate.DataTipRows (end+1) = dataTipTextRow ('T11', repmat(s.CData,1,3),'%.3f');
Pelajar UM
Pelajar UM 2022년 3월 11일
편집: Pelajar UM 2022년 3월 11일
This works perfectly. Thank you so much! One minor issue is that when I run the code, it has already selected a point and showing the data tip before I even interact with the model. Can this be fixed?
Add one more line:
s.DataTipTemplate.DataTipRows(end+1) = dataTipTextRow('Colormap Value',repmat(s.CData,1,3),'%.3f');
delete(dt); % Add this in the last line
or right click on the figure to delete current data tip
Wonderful! Now is it possible to remove X,Y,Z and only keep the colormap value?
Add another line :-)
s.DataTipTemplate.DataTipRows(end+1) = dataTipTextRow('Colormap Value',repmat(s.CData,1,3),'%.3f');
s.DataTipTemplate.DataTipRows(1:3)=[]; % Add this line as well
delete(dt);
Looks great now. Thank you again!

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

추가 답변 (1개)

KSSV
KSSV 2022년 3월 10일

1 개 추천

I don't think you would be able to see the values like that. But you can see what value it has using:
F = scatteredInterpolant(x,y,z,c) ;
ci = F(xi,yi,zi) ; % where xi, yi, zi is the picked point

댓글 수: 5

Thanks. Can I at least output the (xi,yi,zi) values from the probe? ... as in when the user clicks on a point, and not manually entering the coordinates.
I'm getting an error:
d = datacursormode(app.UIAxes2_10);
Error using datacursormode
Invalid figure handle
Choose figure object
f = figure;
ax = gca;
d = datacursormode(f)
d =
DataCursorManager with properties: SnapToDataVertex: on DisplayStyle: 'datatip' DefaultExportVarName: 'cursor_info' Interpreter: 'tex' UpdateFcn: [] Enable: off Figure: [1×1 Figure]
d2 = datacursormode(ax)
Error using datacursormode (line 154)
Invalid figure handle
Thanks, but how do you get the figure object of an UIAxes in app designer?
trisurf(F,P(:,1),P(:,2),P(:,3), flow12, 'Parent', app.UIAxes2_10);
c = colorbar(app.UIAxes2_10);
caxis(app.UIAxes2_10,[0.333 1]);
colormap(app.UIAxes2_10, jet);
c.Label.String = 'T11 Tensor';
On another note, there seems to be a way to modify the data tip function, but I don't really know how to implement customized functions in app designer:

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

카테고리

도움말 센터File Exchange에서 Color and Styling에 대해 자세히 알아보기

질문:

2022년 3월 10일

댓글:

2022년 3월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by