How can I add a table (independent of fig data) under figure?

65 ビュー (過去 30 日間)
egg
egg 2019 年 6 月 12 日
編集済み: Adam Danz 2020 年 1 月 15 日
I want to add a a table (example table below) under one of my figures. I can't use legends because the data for the figure and the table aren't parallel to one another, the table is just a detailed explanation of other components.
Screen Shot 2019-06-12 at 10.23.30 AM.png
  2 件のコメント
Jan
Jan 2019 年 6 月 12 日
編集済み: Jan 2019 年 6 月 12 日
What about using an uitable? What exactly means "under my figure"? A "figure" is the complete window. Do you mean "under a certain axes"?
egg
egg 2019 年 6 月 12 日
Yes, I meant axes! Sorry I'm a little new to the terminology. I can currently make two subplots, and I want to make the second one a table rather than a plot/graph.

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2019 年 6 月 12 日
編集済み: Adam Danz 2019 年 6 月 12 日
In addition to Jan's UI table suggestion, you could convert the table to a character array and use text() to plot the array on an invisible axes. Here's a demo.
% Create table
LastName = {'Sanchez','Johnson','Danz'};
Age = [38,43,40];
Height = [71, 69, 71];
T = table(LastName',Age',Height','VariableNames',{'LastName','Age','Height'});
% plot some data in the main axes
figure()
axes('position',[.1,.4,.8,.5])
plot(Age,Height,'o')
xlabel('Age')
ylabel('Height');
% Convert Table to cell to char array
tableCell = [T.Properties.VariableNames; table2cell(T)];
tableCell(cellfun(@isnumeric,tableCell)) = cellfun(@num2str, tableCell(cellfun(@isnumeric,tableCell)),'UniformOutput',false);
tableChar = splitapply(@strjoin,pad(tableCell),[1;2;3;4]);
% Add axes (not visible) & text (use a fixed width font)
axes('position',[.1,.1,.8,.2], 'Visible','off')
text(.2,.95,tableChar,'VerticalAlignment','Top','HorizontalAlignment','Left','FontName','Consolas');
If you'd like to implement Jan's suggestion to insert a UI table, this should get you started (following the example above).
uit = uitable('Data', table2cell(T),'ColumnName',T.Properties.VariableNames,...
'Units', 'Normalized', 'Position',[0.2,0.05,0.6,0.25]);
  4 件のコメント
egg
egg 2019 年 6 月 12 日
Thank you!
Adam Danz
Adam Danz 2019 年 6 月 12 日
編集済み: Adam Danz 2020 年 1 月 15 日
No problem!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by