Scatter3 : How do I add 4th variable to Data Tips?

I have this code going :
h=scatter3(Lab(2,:),Lab(3,:),Lab(1,:),80,RGB,'fill');
xlabel('b*'),ylabel('a*'),zlabel('L*');
title('CIE-L*a*b* coordinates');
axis([min_Lab(3) max_Lab(3) min_Lab(2) max_Lab(2) min_Lab(1) max_Lab(1)]);grid on;hold on;
% draw black lines indicating axis
line([min_Lab(3) max_Lab(3)],[0 0],[0 0],'color',[0 0 0],'lineWidth',linewidth); % Axis L* == a* == 0
line([0 0],[min_Lab(2) max_Lab(2)],[0 0],'color',[0 0 0],'lineWidth',linewidth); % Axis L* == b* == 0
line([0 0],[0 0],[min_Lab(1) max_Lab(1)],'color',[0 0 0],'lineWidth',linewidth); % Axis a* == b* == 0
% Redefine labels
h.DataTipTemplate.DataTipRows(1).Label = 'b';
h.DataTipTemplate.DataTipRows(2).Label = 'a=';
h.DataTipTemplate.DataTipRows(3).Label = 'L=';
h.DataTipTemplate.DataTipRows(3).Label = 'DE76='; <------ 4th Variable here!
% Show datatip
datatip(h, h.XData(1),h.YData(1),h.ZData(1));
I would like to add a fourth variable to the Data Tip as shown below :
Now, somehow (?), I need to pass the DE76 variable as argument to the datatip() function?
The problem, as I see it, is that datatip seem to only take its arguments from the figure handle, h :
datatip(h, h.XData(1),h.YData(1),h.ZData(1));
How could I possibly access my DeltaE variable, which is sitting in a different array :
DE76 =
0.2309 6.5948 6.3132
20.8147 15.0842 2.2396
0.7225 41.3219 55.9979
1.2122 0.9848 4.2285
I was thinking of, perhaps, adding a fourth row to the LabEpson array which would only contains Lab values otherwise. But they wouldn't be part of the "figure" h structure? This is where I'm lost...
I'll try to find the answer on my own...

Risposte (1)

7 Commenti

So the answer is to change the source of the scatter3 plot? By transfering my data into a Table variable to which I can add the DeltaE values, and specify the source of scatter3 accordingly, like :
tbl = readtable(myData);
s = scatter(tbl.L,tbl.a, tbl.b, tabl.DeltaE, ...);
dt = datatip(s,64,142);
Is 64,142 the row and colum size of the table?
In the example you copied the code from, (64,142) corresponds to the (x,y) coordinates of the datapoint the tip will be shown for.
To create a solution, we need to know how DE76 relates to X,Y and Z values in the scatter plot. Ideally, all 4 are vectors of the same length.
Consider the following sample code, where all four variales are vectors with 12 elements.
Lab = rand(3,12);
DE76 = [0.2309 6.5948 6.3132
20.8147 15.0842 2.2396
0.7225 41.3219 55.9979
1.2122 0.9848 4.2285];
h=scatter3(Lab(2,:),Lab(3,:),Lab(1,:),80,parula(length(Lab)),'fill');
xlabel('b*'),ylabel('a*'),zlabel('L*');
title('CIE-L*a*b* coordinates');
h.DataTipTemplate.DataTipRows(1).Label = 'b';
h.DataTipTemplate.DataTipRows(2).Label = 'a=';
h.DataTipTemplate.DataTipRows(3).Label = 'L=';
row = dataTipTextRow('DE76=',DE76(:));
h.DataTipTemplate.DataTipRows(end+1) = row;
datatip(h, h.XData(1),h.YData(1),h.ZData(1));
I'm almost there.
This is my updated code with your two lines added :
% Redefine labels
h.DataTipTemplate.DataTipRows(1).Label = 'b';
h.DataTipTemplate.DataTipRows(2).Label = 'a=';
h.DataTipTemplate.DataTipRows(3).Label = 'L=';
row = dataTipTextRow('DE76=',DE76(:));
h.DataTipTemplate.DataTipRows(end+1) = row;
% Show datatip
datatip(h, h.XData(1),h.YData(1),h.ZData(1));
Roger Breton
Roger Breton il 22 Dic 2021
Modificato: Roger Breton il 22 Dic 2021
Sorry, I had to continue here...
Then I got this result :
See?
It is perfect for points lieing outside the 3D volume only?
Is there an option to change this behavior?
Sorry, change what behavior?
I am well aware I could always "reason" that, if the 4th element, DeltaE is not being shown when mousing over the point then it's most likely that the color is in gamut and it's DeltaE value would most likely be zero, anyway.
Just curious if such thing would be possible. It maybe a simple option? Otherwise, I'm going to pass on this one and instead concentrate on my next strategy :-)
THANK YOU SO MUCH FOR YOUR INVALUABLE HELP AND PATIENCE!
I don't understand the specifics of the data in your plot, but data tips correspond to actual datapoints in the axes. They should not appear where there is no data. Since DE76 must be the same length as the data on X, Y, and Z, you should always have data for all 4 rows of the data tip.
Your code has changed the datatip template, so that, in this figure, it will always have 4 rows. If there is an (X,Y,Z) datapoint that should not have a DE76 value, you could make that element's value in DE76 be NaN.

Accedi per commentare.

Categorie

Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange

Prodotti

Release

R2021b

Richiesto:

il 22 Dic 2021

Commentato:

il 22 Dic 2021

Community Treasure Hunt

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

Start Hunting!

Translated by