showing empty plot in nexttile or subplot

25 ビュー (過去 30 日間)
Niraj Bal Tamang
Niraj Bal Tamang 2022 年 4 月 25 日
回答済み: Niraj Bal Tamang 2022 年 5 月 3 日
I have 4 classes:
Class A: x=[0.1 0.2 0.3 0.6 0.24 0.67],y=[2 1 4 7 4 5],type=[a b a c d b]
Class B: empty
Class C: x=[0.24 0.4 0.32 0.5 0.1],y=[3 1 4 2 6], type=[c a d c b]
Class D: x=[0.5 0.2 0.4 0.1 0.2],y=[4 1 5 2 6], type=[d d b a c]
I want to generate a 2rows 2 columns group plot (nexttile or subplot or any other possible way) such that I can have plot of xy values based upon the color from type variable (the color of a particular type should be same for all classes, for eg. if color of a is red in Class A, then it should be red in Class B,C and D). I also want to include empty Class B to show that there is no data distribution in Class B. Can anyone please help me with this. Thank you

採用された回答

Chunru
Chunru 2022 年 4 月 26 日
a = "r"; b="g"; c="b"; d="m";
x{1}=[0.1 0.2 0.3 0.6 0.24 0.67];
y{1}=[2 1 4 7 4 5];
t{1}=[a b a c d b]
t = 1×1 cell array
{["r" "g" "r" "b" "m" "g"]}
x{2} = [];
y{2} = [];
t{2} = [];
x{3}=[0.24 0.4 0.32 0.5 0.1];
y{3}=[3 1 4 2 6];
t{3}=[c a d c b];
x{4}=[0.5 0.2 0.4 0.1 0.2];
y{4}=[4 1 5 2 6];
t{4}=[d d b a c];
tiledlayout(2, 2);
for i=1:4
nexttile
hold on
for j=1:length(x{i})
plot(x{i}(j), y{i}(j), "Marker", 'o', "MarkerEdgeColor", t{i}(j), "MarkerFaceColor", t{i}(j))
end
hold off
end
  9 件のコメント
Chunru
Chunru 2022 年 4 月 29 日
Need some tricks to get the legend correct. See above
Niraj Bal Tamang
Niraj Bal Tamang 2022 年 4 月 30 日
Thanks a lot. Yeah, it does seems trickier. I am sorry to say but I think it is still not giving the correct plot. The names seem to get mixed up during concatenation while generating the tall variable. And the x,y value seems to be linked with the random names within tall variable. I have attached the edited x, y and t variables here again after correcting from your first comment. To verify the code, I ran it in these variables but in the first plot with single point, the x and y values are correctly plotted but the name is not matching (It is showing the color of Wairau instead of Conway).

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

その他の回答 (1 件)

Niraj Bal Tamang
Niraj Bal Tamang 2022 年 5 月 3 日
Thanks a lot. I finally got the plot. I removed the = sign from if j>=length(t{i}) line to if j>length(t{i}) and it worked.
for j=1:length(x{i})
if j>length(t{i}) % this is not necessary if t{i} has enough entries
mc = ntypes; % use last color
else
mc = find(t{i}(j)==ut);
end
%mc = find(t{i}(j)==ut);

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by