![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1618758/image.png)
Creating a figure with both a plot and a table
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I want to create a similar figure as the one shown below.
I have tried to google the subject and follow sugestions such as this: https://se.mathworks.com/matlabcentral/answers/466705-how-can-i-add-a-table-independent-of-fig-data-under-figure
However, both of the methods suggested on the similar question isn't giving me the look I'm looking for.
Is it possible to create such a figure as shown below? and does anyone have any suggestions/tips on how it can be solved?
% Table that contains the data for the mean, 10 percentile, 50 percentile and 90 percentile for all months January - December
TableV = [0.8300 0.6100 0.8400 1.0200 0.5500 0.4800 0.4500 0.8100 0.7700 0.7100 1.1100 0.8200; ...
0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400; ...
0.5800 0.3300 0.4600 0.4600 0.0800 0.2500 0.0800 0.2500 0.5400 0.3100 0.5000 0.4600; ...
2.0900 1.4700 1.9500 1.5800 0.8500 1.2500 1.0300 1.5300 1.8200 1.6600 2.1500 1.9500];
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/630530/image.png)
0 comentarios
Respuestas (1)
Abhinav Aravindan
el 16 de Feb. de 2024
Yes, although there is no direct method or function to create a figure using a table as X-axis labels, a possible workaround is to utilize "uifigure," "uiaxes," and "uitable" to achieve a similar result. Below is a code snippet along with the generated output, which can be used to produce a figure similar the one mentioned in your question.
Please find the documentation and a similar MATLAB Answers query for further reference.
Documentation:
clc; clear; close all;
% Data
TableV = [0.8300 0.6100 0.8400 1.0200 0.5500 0.4800 0.4500 0.8100 0.7700 0.7100 1.1100 0.8200; ...
0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400; ...
0.5800 0.3300 0.4600 0.4600 0.0800 0.2500 0.0800 0.2500 0.5400 0.3100 0.5000 0.4600; ...
2.0900 1.4700 1.9500 1.5800 0.8500 1.2500 1.0300 1.5300 1.8200 1.6600 2.1500 1.9500];
% UI Figure and UI Axes
fig = uifigure('Position', [200 400 1000 600], 'Color', [1 1 1]);
ax = uiaxes(fig, 'Position', [183 206 720 320]);
% Plotting Data
plot(ax, 1:12, TableV(1,:));
hold(ax,'on');
plot(ax, 1:12, TableV(2,:));
plot(ax, 1:12, TableV(3,:));
plot(ax, 1:12, TableV(4,:));
hold(ax,'off');
% Axes Properties
grid(ax, 'minor');
ylabel(ax, "Duration-days");
title(ax, "U < 15 m/s for 12 hours");
ax.MinorGridLineStyle = '-';
ax.XLim = [0.5 12.5];
ax.YLim = [-0.4 2.5];
ax.XTickLabel = [];
legend(ax, {'Mean', 'P10', 'P50', 'P90'}, 'Location', 'eastoutside');
% Add Table
T = array2table(TableV);
Tlegend = table(["Mean"; "P10"; "P50"; "P90"]);
T = [Tlegend T];
T.Properties.VariableNames = ["Legend" "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"];
uitable(fig, 'Data', T, 'Position', [160 88 650 122.5], 'ColumnWidth','fit', 'BackgroundColor', [1 1 1]);
% Save Figure
exportapp(fig, "plots.png");
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1618758/image.png)
0 comentarios
Ver también
Categorías
Más información sobre Data Distribution Plots 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!