MATLAB Answers

Adding Custom Data Tip to 3D UIAxes slice() plot

20 views (last 30 days)
Eric Blassick
Eric Blassick on 14 Mar 2020
Commented: Eric Blassick on 15 Mar 2020
I have been working on a project in the app designer which involves thermal analysis of a 3D object. This is 3+1 dimensional data with position X,Y,Z as well as temperature T data at each point, represented by color. To display the temperature distribution, I have been using the slice() command.
I would like to modify the default data tip in the the uiaxis plot to display the default X,Y, and Z values as well as the temperature T value when hovering or clicking on a point. Below is example code that I've written.
% Some definitions
x = 0:10;
y = 0:10;
z = 0:10;
[X,Y,Z] = meshgrid(x,y,z);
V = sqrt(X.*Y.*Z);
%Defining slice through volume
xslice = [5];
%Plotting using slice()
ax = uiaxes;
cla(ax);
slice(ax,X,Y,Z,V,xslice,[],[]);
colorbar(ax)
%Initializing ax.Children.DataTipTemplate property
dt = datatip(ax.Children);
delete(dt);
%Attempting to add 4th row to datatip
row = dataTipTextRow('T',ax.Children.CData);
ax.Children.DataTipTemplate.DataTipRows(end+1) = row;
% Error using matlab.graphics.datatip.DataTipTemplate/set.DataTipRows
% Value must be compatible with the data source.
%
% Error in Datatip_Test (line 24)
% ax.Children.DataTipTemplate.DataTipRows(end+1) = row
I wish to add a 4th row to the default datatip. I have read and tried this tutorial but I have run into the same issues described in the comment of This thread. The comment shows exactly what I have tried and the resulting errors I have been getting. Ultimately, the problem is getting the "row" object to be accepted by the DataTipRows property. The documentation for dataTipTextRow() suggests that a vector may be used in the Value field of the "row" object, but the surface is 2D data and requires a 2D matrix. As a result, I get the following error when attempting the following assignment :
ax.Children.DataTipTemplate.DataTipRows(end+1) = row;
% Error using matlab.graphics.datatip.DataTipTemplate/set.DataTipRows
% Value must be compatible with the data source.
%
% Error in Datatip_Test (line 24)
% ax.Children.DataTipTemplate.DataTipRows(end+1) = row
This error code is cryptic and I cannot determine why the error is being given. I suspect that set.DataTipRows only accepts vectors, but what is required here is a 2D matrix input as the data is 2D.
The glorious solution would be to use
%Attempting to add 4th row to datatip
row = dataTipTextRow('T','CData');
ax.Children.DataTipTemplate.DataTipRows(end+1) = row;
But alas, 'CData' is not supported like 'XData' or 'YData' etc. and so this gives the following error:
%Error using matlab.graphics.datatip.DataTipTemplate/set.DataTipRows
%Value must be a string scalar or a character vector with the name of a data property, such as 'XData', or it must be
%a vector or a function handle.
%
%Error in Datatip_Test (line 24)
%ax.Children.DataTipTemplate.DataTipRows(end+1) = row;
I would appreciate suggestions to add this 4th row to the DataTipTemplate property, or any possible workarounds.

  0 Comments

Sign in to comment.

Answers (1)

Cameron B
Cameron B on 15 Mar 2020
Not sure if this is what you’re looking for, but this may help. https://www.mathworks.com/matlabcentral/answers/497552-hi-when-you-create-a-plot-and-hover-over-a-data-point-without-pressing-anything-a-datatip-is-displa

  1 Comment

Eric Blassick
Eric Blassick on 15 Mar 2020
Unfortunately this approach does not work for 3D plots. Though a row object can be created with a 2D Value matrix, it is not accepted when attempting the following assignment:
ax.Children.DataTipTemplate.DataTipRows(end+1) = row;
% Error using matlab.graphics.datatip.DataTipTemplate/set.DataTipRows
% Value must be compatible with the data source.
%
% Error in Datatip_Test (line 24)
% ax.Children.DataTipTemplate.DataTipRows(end+1) = row

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!