Need more colours for scatter plot with multiple datasets

조회 수: 3 (최근 30일)
Craig Saunders
Craig Saunders 2021년 1월 6일
편집: Cris LaPierre 2021년 1월 6일
Hi there,
I'm currently plotting 11 datasets onto one single figure as Scatter. Each dataset is a Speed. MATLAB has a default number of colours (7 in total, excluding white) however it then just repeats itself starting over again. I need to ensure I can differentiate the different Speeds with 11 different colours. How is this possible?
Please see snippet of code below:
p(1) = scatter(REF_MASS_LT_14000_0kt.REL_WIND_DIR_avg,REF_MASS_LT_14000_0kt.COLLECTIVE_avg___,75,'filled','DisplayName','0kt');
p(2) = scatter(REF_MASS_LT_14000_5kt.REL_WIND_DIR_avg,REF_MASS_LT_14000_5kt.COLLECTIVE_avg___,75,'filled','DisplayName','5kt');
p(3) = scatter(REF_MASS_LT_14000_10kt.REL_WIND_DIR_avg,REF_MASS_LT_14000_10kt.COLLECTIVE_avg___,75,'filled','DisplayName','10kt');
p(4) = scatter(REF_MASS_LT_14000_15kt.REL_WIND_DIR_avg,REF_MASS_LT_14000_15kt.COLLECTIVE_avg___,75,'filled','DisplayName','15kt');
p(5) = scatter(REF_MASS_LT_14000_20kt.REL_WIND_DIR_avg,REF_MASS_LT_14000_20kt.COLLECTIVE_avg___,75,'filled','DisplayName','20kt');
p(6) = scatter(REF_MASS_LT_14000_25kt.REL_WIND_DIR_avg,REF_MASS_LT_14000_25kt.COLLECTIVE_avg___,75,'filled','DisplayName','25kt');
p(7) = scatter(REF_MASS_LT_14000_30kt.REL_WIND_DIR_avg,REF_MASS_LT_14000_30kt.COLLECTIVE_avg___,75,'filled','DisplayName','30kt');
p(8) = scatter(REF_MASS_LT_14000_35kt.REL_WIND_DIR_avg,REF_MASS_LT_14000_35kt.COLLECTIVE_avg___,75,'filled','DisplayName','35kt');
p(9) = scatter(REF_MASS_LT_14000_40kt.REL_WIND_DIR_avg,REF_MASS_LT_14000_40kt.COLLECTIVE_avg___,75,'filled','DisplayName','40kt');
p(10) = scatter(REF_MASS_LT_14000_45kt.REL_WIND_DIR_avg,REF_MASS_LT_14000_45kt.COLLECTIVE_avg___,75,'filled','DisplayName','45kt');
p(11) = scatter(REF_MASS_LT_14000_50kt.REL_WIND_DIR_avg,REF_MASS_LT_14000_50kt.COLLECTIVE_avg___,75,'filled','DisplayName','50kt');
% Plotting settings
title('Merlin CN - Collective (%) vs Azimuth (deg) - [<= 14000kg]');
xlabel('Azimuth (deg)');
ylabel('Collective (%)');
xlim([-180 180])
grid
grid minor
ax = gca;
ax.YAxisLocation = 'origin';
lgd_1 = legend('Location','northeastoutside');
lgd_1.Title.String = 'Collective (%) - Airspeeds';
legend(p([1 2 3 4 5 6 7 8 9 10 11]),'0kt','5kt','10kt','15kt','20kt','25kt','30kt','35kt','40kt','45kt','50kt');
Instead of individually assigning different colours to each plot, is there a way this can be done automatically to each of the 11 datasets?
Many thanks in advance!
  댓글 수: 2
Craig Saunders
Craig Saunders 2021년 1월 6일
Thank you Stephen for your prompt response - sorry I am quite new to MATLAB, would you be kind enough to show an example using my code provided?
Many thanks,

댓글을 달려면 로그인하십시오.

답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 1월 6일
편집: Cris LaPierre 2021년 1월 6일
The answer provided here doesn't do maximally distinct colors, but does show how to increase the number of colors used to plot on the same plot (colororder axis property).
You can read more here, here and here. Just note that the colororder function was introduced in R2019b, so you won't be able to use that in R2018b, but the property is still there, so the link will still help you understand how it works. The linked answer directs you to a page that shows how to modify the axis property without it.

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by