Filter löschen
Filter löschen

Need more colours for scatter plot with multiple datasets

4 Ansichten (letzte 30 Tage)
Craig Saunders
Craig Saunders am 6 Jan. 2021
Bearbeitet: Cris LaPierre am 6 Jan. 2021
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 Kommentare
Craig Saunders
Craig Saunders am 6 Jan. 2021
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,

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Cris LaPierre
Cris LaPierre am 6 Jan. 2021
Bearbeitet: Cris LaPierre am 6 Jan. 2021
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.

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by