Spider Plot with Standard Deviation as shaded region
古いコメントを表示
I want to plot a spider plot where each spoke represents the average value with solid line. In addition, I want to show standard deviation as shaded region around the average plot (Average+SD and Average-SD). I have attached a figure to show the desired outcome.
Figure available at: https://www.mdpi.com/2078-2489/15/6/364
Thank you in advance.
2 件のコメント
Mathieu NOE
2025 年 4 月 4 日
you can probably add the shaded area in this existing code :
Ayesha Tooba Khan
2025 年 4 月 4 日
編集済み: Ayesha Tooba Khan
2025 年 4 月 6 日
採用された回答
その他の回答 (1 件)
You can do it like this:

I am not aware of a function, so you have to do it on your own.
Note that this functions uses values maxval = 7 and offset = 4 that are tailored to your data to have an axis running from -4 to 3.
Your friend is pol2cart to convert all the polar stuff to Cartesian coordinates and then use plot, patch or line commands.
function spiderplot(val, sd, col)
if nargin < 1
val = [-1 -1 1 -1 -1 -1 0];
end
if nargin < 2
Nspokes = size(val, 2);
sd = ones(1, Nspokes) + 0.5*rand(1, Nspokes);
end
if nargin < 3
col = 'r'; % or [234 170 58]/266; or 'g' or any other color
end
labels = {'Degree', 'Density', 'Betweeness Centrality', 'Closeness', 'Eigenvector', 'Transivity', 'Entropy'};
offset = 4; % map the smallest value to 0
maxval = 7;
val = val + offset;
Nspokes = size(val, 2);
theta = linspace(0, 2*pi, Nspokes + 1);
%% plot the axes (background, circles and spokes)
% add a grayish background circle
col_bg = [229, 236, 246]/255;
Npoints = 100;
thetaN = linspace(0, 2*pi, Npoints);
[xc, yc] = pol2cart(thetaN, maxval);
patch(xc, yc, col_bg, 'EdgeColor', 'none')
hold on
% add the spokes
for i = 1:Nspokes
[xs, ys] = pol2cart(theta(i), maxval);
line([0, xs], [0, ys], 'Color', 'w')
end
% add the circles
for i = 1:maxval
[xc, yc] = pol2cart(thetaN, i);
plot(xc, yc, 'w-')
end
% label the axis
for i = 0:maxval
str = int2str(i - offset);
% change dash to minus:
str = strrep(str, '-', char(hex2dec('2212')));
text(i, 0, str, 'FontSize', 14,...
'HorizontalAlignment', 'center', 'VerticalAlignment', 'top')
end
axis off
%% plot the data
% append first element to plot a closed curve
val = [val, val(:, 1)];
sd = [sd, sd(:, 1)];
% plot data
[x, y] = pol2cart(theta, val); % convert to Cartesian
plot(x, y, '-', 'Color', col)
hold on
% plot sd lines
[x1, y1] = pol2cart(theta, val - sd);
[x2, y2] = pol2cart(theta, val + sd);
plot(x1, y1, '--', 'Color', col)
plot(x2, y2, '--', 'Color', col)
% shade the area between the +/- SD lines
h = patch([x1 fliplr(x2)], [y1 fliplr(y2)], col,...
'EdgeColor', 'none', 'FaceAlpha', 0.2);
カテゴリ
ヘルプ センター および File Exchange で Uniform Distribution (Continuous) についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



