How to draw a plot like this in MATLAB instead of using SigmaPlot
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nourhan
am 17 Aug. 2023
Kommentiert: Nourhan
am 31 Aug. 2023
Hello,
Is there a way of plotting a similar graph to the one shown below using MATLAB?

1 Kommentar
Dyuman Joshi
am 17 Aug. 2023
It is possible to plot like this, but that would require using a bunch of different functions -
I am not sure about the grey patches. Are they boxplots?
Akzeptierte Antwort
akshatsood
am 31 Aug. 2023
Bearbeitet: akshatsood
am 31 Aug. 2023
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]);

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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!