How to stackedplot with text data

13 visualizaciones (últimos 30 días)
Life is Wonderful
Life is Wonderful el 29 de Nov. de 2019
Comentada: Life is Wonderful el 19 de Abr. de 2021
I have uit.Data and i want to use "stackedplot" to display the information from the table.
I want to plot below table x & y coordinates.
where x for WeirdDuration and y for text data
  1 comentario
Adam Danz
Adam Danz el 2 de Dic. de 2019
While it's fairly straightforward to plot table data using the line below, I don't think adding text is supported.
To add text, you would need to supply the axes handle in order to specify which axes the test should be added to but stackedplot does not return axis handles so there's no way (I know of) to add things to a stakedplot axes. It's a fairly new feature (r2018b) so maybe that functionality will be added in the future.
Instead, I recommend creating your own subplot axes and use linkaxes to link the axis ranges. The vertical line won't appear but you could add grids so it's easy to visually compare subplots.

Iniciar sesión para comentar.

Respuesta aceptada

Adam Danz
Adam Danz el 2 de Dic. de 2019
Editada: Adam Danz el 19 de Nov. de 2020
** UPDATE**
Almost a year later I learned of a way to add text to stackedplot axes. See this answer:
** Original answer showing alternative solution **
I'm assuming you're positioning text according to this screen shot you shared in an earlier question. Since text cannot currently be added to stackedplot axes (as for r2019b, let's hope that changes), here are two workarounds
Use an alternative function
(added on 11/19/20)
stackedaxes() on the file exchange is a limited alternative to Matlab's stackedplot and returns the axis handles so that you can add to or modify the plot after it is created.
Create your own custom stacked axes
Create axes, link their x-axis limits, and then add text to each axes.
% Create input table for demo because OP did not provide table
T = table((duration(0,0,17):seconds(1):duration(0,0,20))',...
{'abc','','bcd','cde'}',...
{'test1','','test3','test4'}',...
{'autoserv1','','autoserv3','autoserv4'}',...
'VariableNames',{'WeirdDuration','lot_test','Sublog','Message_test'})
T = 4x4 table
WeirdDuration lot_test Sublog Message_test _____________ __________ __________ _____________ 00:00:17 {'abc' } {'test1' } {'autoserv1'} 00:00:18 {0×0 char} {0×0 char} {0×0 char } 00:00:19 {'bcd' } {'test3' } {'autoserv3'} 00:00:20 {'cde' } {'test4' } {'autoserv4'}
% The only input would be "T", the table created above. It is assumed that
% The x values are stored in the first column named 'WeirdDuration' and that
% a subplot should be created for each subsequent column in T.
% Create figure with linked subplots stacked vertically
fig = figure();
nSub = size(T,2)-1; %number of subplots assuming 1 subplot for each col of T except the first
% in order to maximize spaces, create subplots manually.
margins = [.11 .11 .08 .12 .01]; %margins: left, right, bottom, top, vertical space between plots
height = (1-sum(margins(3:4)) - (nSub-1)*margins(5))/nSub; %height of each subplot
width = 1-sum(margins(1:2)); % width of each subplot
subPos = margins(3):height+margins(5):1; %vertical position of each subplot from bottom to top (may have extra values at end)
subHand = arrayfun(@(i)axes(fig,'Position',[margins(1),subPos(i),width,height]),1:nSub);
% add grids
set(subHand,'XGrid','on') % you could add 'YGrid','on' if you wish
% How loop through each subplot (i) and add text from column i+1
x = T.WeirdDuration; % the x coordinates of your text
y = 1:size(T,1); % the y coordinates of your text
for i = 1:nSub
th = text(subHand(i), x, y, T{:,i+1},'VerticalAlignment','Bottom');
ylim(subHand(i),[min(y),max(y)+1])
xlim(subHand(i),[min(x),max(x)+range(x)*.1]) %adds 10% of axis range
end
% Link x axes so the x limits are always the same
linkaxes(subHand,'x');
% Remove x tick for all but bottom axes
set(subHand(2:end),'XTickLabel', [])
  5 comentarios
Life is Wonderful
Life is Wonderful el 5 de Dic. de 2019
I have raised new thread. Can you please look into it
Thank you!!

Iniciar sesión para comentar.

Más respuestas (1)

Duncan Po
Duncan Po el 2 de Dic. de 2019
What do you expect to see with your text data in the plot?
stackedplot ignores text data, but plots categorical data. If your text data can be converted into categorical (contains only a relatively small number of choices), you should convert and then plot. There is a convertvars function that can do the conversion for you.
  1 comentario
Life is Wonderful
Life is Wonderful el 19 de Abr. de 2021
@Adam Danz, Hi Adam,
I having facing difficulties for generating the twiddle factor lookUp table using cordic sine and cordic cosine
Thank you!

Iniciar sesión para comentar.

Categorías

Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by