How to draw a plot like this in MATLAB instead of using SigmaPlot

Hello,
Is there a way of plotting a similar graph to the one shown below using MATLAB?

1 件のコメント

Dyuman Joshi
Dyuman Joshi 2023 年 8 月 17 日
It is possible to plot like this, but that would require using a bunch of different functions -
Check out - plot, annotation, text
I am not sure about the grey patches. Are they boxplots?

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

 採用された回答

akshatsood
akshatsood 2023 年 8 月 31 日
編集済み: akshatsood 2023 年 8 月 31 日

0 投票

Hi Nourhan,
I understand that you wish to draw a plot similar to the screenshot attached in the question. As per my understanding, a closely related figure could be achieved by using the boxplot function. Here is the code snippet to plot the figure using random data with some of the specifications resembling with the screenshot attached.
x = abs(100*randn(100,25)); % assuming a random data
bp = boxplot(x,'Color','k'); % create a boxplot for multiple groups
% extract upper and lower whiskers from the box plot and hide them
whiskers = findobj('-regexp','Tag','(Lower|Upper) (Whisker|Adjacent Value)');
set(whiskers,'LineStyle','none')
% select outliers and delete them
h = findobj(gca,'tag','Outliers');delete(h)
% get the handles of the individual boxes
h = findobj(gca, 'Tag', 'Box');
numBoxes = numel(h);
numToColor = 8; % number of boxes to color
% create a vector of random indices to color the boxes
indicesToColor = randperm(numBoxes, numToColor);
for i = 1:numel(h) % iterate through all boxes
x = mean(h(i).XData([1, 3])); % x-coordinate of the marker
yTop = max(h(i).YData); % y-coordinate of the top marker
yBottom = min(h(i).YData); % y-coordinate of the bottom marker
hold on;
plot(x, yTop, 'ks', 'MarkerSize', 5, 'MarkerFaceColor','black'); % set top marker
plot(x, yBottom, 'k^', 'MarkerSize', 5, 'MarkerFaceColor','black'); % set bottom marker
hold off;
end
% coloring random box plots
for i = 1:numToColor
patch(get(h(indicesToColor(i)),'XData'),get(h(indicesToColor(i)),'YData'), ...
[0.5 0.5 0.5], 'FaceAlpha',.5);
end
xlabel('Year');
ylabel('(T&A days)');
ylim([0 160]);
For adding annotations, you can leverage annotation function to add arrows at the required places.
The script attached above outlines a workflow which can be carried forward to achieve the plot with your data combined with required modifications from your end.
Have a look at the below references for better understanding
I hope this helps.

1 件のコメント

Nourhan
Nourhan 2023 年 8 月 31 日
This helps a lot, thank you so much.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

タグ

質問済み:

2023 年 8 月 17 日

コメント済み:

2023 年 8 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by