Issue with TickLabelInterpreter using uifigure
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tommaso Mastropasqua
el 17 de Feb. de 2023
Comentada: Tommaso Mastropasqua
el 21 de Abr. de 2023
I need to display the tick labels on multiple lines and I was able to come up to a good solution using latex code. Unfortunately, this solution doesn't work when using uifigure(). Any tips?
tmpLabels = {'Session 1','Session 2','Session 3','Session 4'};
tmpLabels2 = {'(Condition 1)','(Condition 2)','(Condition 1)','(Condition 2)'};
n = numel(tmpLabels);
tmpLabels3 = cell(1,n);
for tmpId = 1:n
tmpLabels3{tmpId} = sprintf('\\begin{tabular}{c} %s \\\\ %s \\end{tabular}',tmpLabels{tmpId},tmpLabels2{tmpId});
end
% This works fine
tmpF = figure('Position',[650,550,700,400]);
tmpT = tiledlayout(tmpF,1,3,'TileSpacing','tight','Padding','compact');
title(tmpT,'Figure');
tmpAx = nexttile(tmpT,[1 2]);
set(tmpAx,'XLim',[0.8 4.2],'XTick',1:4,'XTickLabel',tmpLabels3,'TickLabelInterpreter','latex','Box','on','YGrid','on')
% The same code doesn't work when using uifigure() in place of figure()
tmpUiF = uifigure('Position',[650,550,700,400]);
tmpUiT = tiledlayout(tmpUiF,1,3,'TileSpacing','tight','Padding','compact');
title(tmpUiT,'UI Figure');
tmpUiAx = nexttile(tmpUiT,[1 2]);
set(tmpUiAx,'XLim',[0.8 4.2],'XTick',1:4,'XTickLabel',tmpLabels3,'TickLabelInterpreter','latex','Box','on','YGrid','on')
2 comentarios
Ryan Romeo
el 17 de Feb. de 2023
Editada: Walter Roberson
el 21 de Abr. de 2023
I'm assuming here that you definitely want to use the 'latex' interpreter, and you don't want to use a workaround that involves manually positioning text boxes.
I found a passable way to do it without using the \tabular LaTeX environment. Curiously, the line break (\\) only registers when I put the entire label into a math environment (between $ symbols). Each row of text is enclosed in a \text environment to avoid the math environment font. Also since I dropped the table environment, the code loses its centering properties, so I manually shifted the top row with ~'s. See code below:
% New label cell array
tmpLabels4 = cell(1,n);
for tmpId = 1:n
tmpLabels4{tmpId} = [ '$~~~~\text{' tmpLabels{tmpId} '}\\ \text{' tmpLabels2{tmpId} '}$' ];
end
If you insert the above code before your 'uifigure' code, and then change the 'XTickLabel' argument from tmpLabels3 to tmpLabels4, it should give you something close to what the regular figure's labels looks like.
Tommaso Mastropasqua
el 19 de Feb. de 2023
Editada: Walter Roberson
el 19 de Feb. de 2023
Respuestas (1)
Divyanshu
el 21 de Abr. de 2023
This solution is for the error you are getting while exporting the figure into a file.
One possible workaround to resolve the issue is by using ‘exportgraphics’ function instead of the ‘exportapp’.
The reason is that the ‘exportapp’ function is not able to export the figure into the file because of the ‘success-icon’ added to the cells of the table ‘tmpUit’, just before exporting the figure.
Please refer the following documentation for further information about ‘exportgraphics’ function:
(Note: The above workaround is for the second problem, one you mentioned in the comments.)
Ver también
Categorías
Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!