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

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일
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.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, 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