Info

此问题已关闭。 请重新打开它进行编辑或回答。

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

1 次查看(过去 30 天)
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

回答(1 个)

Paul Wolfram
Paul Wolfram 2019-9-20
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

此问题已关闭。

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by