필터 지우기
필터 지우기

Creating a figure with both a plot and a table

조회 수: 6 (최근 30일)
Mari Sandvik
Mari Sandvik 2021년 5월 26일
답변: Abhinav Aravindan 2024년 2월 16일
Hi,
I want to create a similar figure as the one shown below.
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];

답변 (1개)

Abhinav Aravindan
Abhinav Aravindan 2024년 2월 16일
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");

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by