フィルターのクリア

Is there a way to build a defined set of colors which the gscatter command to accept?

7 ビュー (過去 30 日間)
Earlier this year I built a MATLAB script which produces group scatter plots for up to 8 data sets. This is a sample of that code;
% Setup the group scatter plot
figure('Name','Measured Values');
colors = 'rgbcmykw'; % MATLAB’s default predefined color spec
h = gscatter(T_Time, Rad_Val, Leg_Nom, colors, 'o', 15, 'on');
for n = 1:length(h)
set(h(n), 'MarkerFaceColor', colors(n));
end
set(gca,'YScale','log');
% Change the semilog labels to decimal units
New_YTickLabel = get(gca,'Ytick');
set(gca,'YTickLabel',New_YTickLabel);
This code works well for the most part. The drawback being an 8th data set plotted in white (where I manually change the color from white to grey).
But now I’ve been asked to modify this code to account for up to 12 data sets. Knowing that there are only 8 pre-defined colors, I suspected MATLAB would throw an error since the number of data sets exceeds the number of available colors. And it did. The exact error reads as follows:
Index exceeds matrix dimensions
It points to this line of code: set(h(n), 'MarkerFaceColor', colors(n));
Since there are only 8 pre-defined, hard coded colors in MATLAB, I’m looking for a method/technique to build a pallet of 12 colors. These 12 colors would be used by the gscatter command and in the for loop.
Can this be done?

採用された回答

Walter Roberson
Walter Roberson 2014 年 3 月 31 日
Instead of using a color name letter, use an RGB vector.
colors = [1 0 0; 0 1 0; 0 0 1; 0 1 1; 1 1 0; 1 0 1; 0 0 0; 1 1 1 ...] %recheck the values
set(h(n), 'MarkerFaceColor, colors(n,:))
  2 件のコメント
Brad
Brad 2014 年 3 月 31 日
Walter, thank you. This works just fine!!
Image Analyst
Image Analyst 2014 年 3 月 31 日
You can use a whole bunch of pre-named colormaps if you want, for example, make colormap with 100 colors:
colors = jet(100); % Or can use hot, winter, cool, autumn, etc.....

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by