Does anyone know how to create colors?
Show older comments
Hello everyone,
How can I create/ have different colors from the standard ones (i.g. 'g','r','b','m'...)?
Thank you.
Accepted Answer
More Answers (1)
Image Analyst
on 16 Aug 2021
Try this:
% Create 20 different colors according to the jet color map.
colors = jet(20);
% Plot randome data, each curve with one of the colors we created.
% Basically you have to get the color equal to one row from colors.
for k = 1 : size(colors, 1)
thisColor = colors(k, :);
y = rand(1, 5) + 2 * k; % Create some random data.
plot(y, '.-', 'Color', thisColor, 'LineWidth', 4, 'MarkerSize', 50); % Plot this one curve.
hold on; % Don't let subsequent plots blow away this one we just drew.
end
grid on;
xlabel('X');
ylabel('Y');

3 Comments
Pul
on 16 Aug 2021
Image Analyst
on 17 Aug 2021
light_blue = [0.5 0.5 1];
plot(1:12, randn(1,12), 'color', light_blue)
If you have created a list of lots of colors, like in my example, and, for example, you want to make the curve with the 10th color from the list, you can do
plot(y, '.-', 'Color', colors(10, :), 'LineWidth', 4, 'MarkerSize', 50); % Plot this one curve.
My demo showed that, where I plotted every color from k=1 to k=20.
Pul
on 17 Aug 2021
Categories
Find more on Spline Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!