plot title formatting with table

3 vues (au cours des 30 derniers jours)
Kiran Karra
Kiran Karra le 22 Août 2016
I have a figure with many subplots, and each subplot has an associated "metric." Normally, you'd put the metric in the title of the figure ... but suppose I am trying to compare 5 different metrics for each subplot. Is there a nice way to display all 5 of them in the title without it looking too crowded?
I suppose one approach is something like this ...
but even this looks cumbersome, and I don't know if it is possible to put tables in titles in Matlab?
Any suggestions are greatly appreciated!
Cheers,

Réponses (2)

Walter Roberson
Walter Roberson le 23 Août 2016
title() does permit 'Interpreter', 'latex' so you might be able to use the File Exchange contribution https://www.mathworks.com/matlabcentral/fileexchange/44274-latextable
However, I would not be surprised if it assumes does not get the spacing right between the title and the graph.

Tillmann
Tillmann le 26 Sep 2018
I was just looking for the same and tried out the latextable option. For me it didn't work, because of the table environment. However if you directly use the tabular environment, it does work.
MWE:
tbl_header = "\begin{tabular}{ccccc} \textbf{DoE ID} & \multicolumn{2}{c}{\textbf{Toolposition} (in mm)} & \multicolumn{2}{c}{\textbf{Material}} \\ & x & y & name & thickness (in mm) \\ \hline";
tbl_footer = "\end{tabular}";
for ii = 1:5
plot((1:256)', rand(256,1)); hold on;
tbl_body(ii) = sprintf("%d & %.2f & %.2f & %s & %.2f", randi(10,1), rand, rand, 'random string', randi(10,1));
end
tbl_str = sprintf("%s %s %s", tbl_header, strjoin(tbl_body, ' \\\\ '), tbl_footer);
title(...
{...
sprintf("\\textbf{Machine:} %s", 'Random machine name'), ...
"", ...
tbl_str ...
}, ...
'Interpreter','latex' ...
);

Community Treasure Hunt

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

Start Hunting!

Translated by