How to change the colour of the markers on a scattered graph?

36 ビュー (過去 30 日間)
Hyeonjun Park
Hyeonjun Park 2021 年 7 月 13 日
コメント済み: Star Strider 2021 年 7 月 15 日
Hi all,
I have a data set which is 5 * 1 double (BMC_14_whole_sum) which is like 8.5, 8.8, 9.3 etc and I am plotting that in a boxplot and scatter graph to show where exactly the markers are. Below is what I have tried so far:
BMC_14_whole_sum = sum(BMC_14_whole,2);
boxplot(BMC_14_whole_sum)
hold on
scatter(ones(size(BMC_14_whole_sum)).*(1+(rand(size(BMC_14_whole_sum))-0.5)/10),BMC_14_whole_sum, 'filled')
hold off
title('BMC Whole W14')
I have attached my .mat file. The image above is something similar to what I get. I would like to have those 5 different markers to have 5 different colours and possibly 5 different marker styles as well. How can I do that? Also, if there is a simpler codes to plot the scatter graph rather than using (ones(size(BMC_14_whole_sum)).*(1+(rand(size(BMC_14_whole_sum))-0.5)/10),BMC_14_whole_sum), please suggest me too.
Thank you so much for the help

採用された回答

Star Strider
Star Strider 2021 年 7 月 14 日
Try this —
LD = load('aw_w14_scans.mat');
BMC_14_whole = LD.BMC_14_whole;
BMC_14_whole_sum = sum(BMC_14_whole,2);
boxplot(BMC_14_whole_sum)
hold on
scatter(ones(size(BMC_14_whole_sum)).*(1+(rand(size(BMC_14_whole_sum))-0.5)/10),BMC_14_whole_sum, [], (1:numel(BMC_14_whole_sum)), 'filled')
colormap(jet)
hold off
title('BMC Whole W14')
The colours are defined here by ‘(1:numel(BMC_14_whole_sum))’. Choose whatever colormap you want.
There is nothing similar to colororder for markers, so changing the markers would require a loop.
mv = 'psdo^';
cm = colormap(jet(numel(BMC_14_whole_sum)))
xv = ones(size(BMC_14_whole_sum)).*(1+(rand(size(BMC_14_whole_sum))-0.5)/10);
yv = BMC_14_whole_sum;
figure
boxplot(BMC_14_whole_sum)
hold on
for k = (1:numel(BMC_14_whole_sum))
scatter(xv(k), yv(k), [], cm(k,:), 'filled', 'Marker',mv(k))
end
hold off
title('BMC Whole W14')
.
  6 件のコメント
Hyeonjun Park
Hyeonjun Park 2021 年 7 月 15 日
oh alright thank you!
Star Strider
Star Strider 2021 年 7 月 15 日
As always, my pleasure!
.

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

その他の回答 (2 件)

ANKUR KUMAR
ANKUR KUMAR 2021 年 7 月 13 日
I don't think I understood your question completely. Please do attach sample data (probably in a .mat file) and your complete code. But I picked a line, and trying to answer that.
Answering this question:
" I can't seem to find a way. I would like to have 5 different markers to have 5 different colours. How can I do that?"
x = linspace(0,1*pi,200);
y = cos(x) + rand(1,200);
cols={'r','b','g','m','k'}; % If you want random colors, you can just simply generate RGB random numbers using randi commmand
markers={'d','o','+','^','*'};
for index=1:5
scatter(x,sin(x*index),cols{index},markers{index})
hold on
end
legend(strcat('Sin ',{' '},string([1:5]),'x'),'box','off','location','best')
  3 件のコメント
ANKUR KUMAR
ANKUR KUMAR 2021 年 7 月 14 日
@Star Strider properly answered your question. I don't want to repeat the code. Refer to his answer.
Hyeonjun Park
Hyeonjun Park 2021 年 7 月 15 日
Alright thank you Ankur!

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


Steven Lord
Steven Lord 2021 年 7 月 14 日
See the "Vary Circle Color" and "Fill the Markers" examples on the documentation page for the scatter function.

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by