Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Looped subplot with different marker face colors for each data point within each subplot

1 vue (au cours des 30 derniers jours)
Paul Wolfram
Paul Wolfram le 20 Sep 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hi collective brain,
I am trying to create 24 subplots where colors differ for each data point within each subplot, but are repeated in each subplot. Please see both a screenshot and my code below (working example). As you can see in each subplot all markers are green, although I would like them to be red, green, blue, red, green, blue, red, green (as indicated in vector scatter_clr). How do I fix this? If someone could also help me understand how I can use color triplets, .e.g [1 0 1], instead of characters that would be of great help too.
Thanks in advance for any hints!
x_data = rand(8,24);
y_data = rand(8,24);
scatter_clr = ['r';'g';'b';'r';'g';'b';'r';'g'];
scatter_clr = repmat(scatter_clr,1,24);
figure
for j = 1:8;
for k = 1:24;
subplot(6,4,k)
scatter1 = scatter(x_data(:,k)/1000, y_data(:,k)/1000, [], scatter_clr(j,k),'filled');
end
end

Réponses (1)

Paul Wolfram
Paul Wolfram le 20 Sep 2019
Think I just figured the first part out, see below. Still wondering how to use triplets. Thanks
example_scatter_plot2.JPG
clc
clear
close all
x_data = rand(8,24);
y_data = rand(8,24);
scatter_clr = {'r';'g';'b';'r';'g';'b';'r';'b'};
scatter_clr = repmat(scatter_clr,1,24);
figure
for j = 1:8;
for k = 1:24;
subplot(6,4,k)
scatter1(j) = scatter(x_data(j,k), y_data(j,k), [], scatter_clr{j,k},'filled');
hold on
end
end

Cette question est clôturée.

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by