Removing additional points from scatter plot

15 visualizaciones (últimos 30 días)
Prasad Joshi
Prasad Joshi el 11 de Feb. de 2022
Comentada: Prasad Joshi el 11 de Feb. de 2022
How can I removed this additional legend data and keep only 2kw , 3kw and 4 kw and remove additional data points from legend of scatter plot ..Thank you in advance
The code That i used
A=xlsread('Compare_All_cases','B9:AB9');
i= 1
x1=ones(1,3);
y1=A(:,(i:(i+2)))
hold on
a=scatter(x1,y1,'filled','r')
xtics=[0:1:4];
xticlab={'' '20sec' '35sec' '50sec' ''};
set(gca,'XTick',xtics,'XTickLabel',xticlab,'Fontsize', 10)
text(x1(1),y1(1),sprintf(' (%.1f)[55 55]',y1(1)))
text(x1(2),y1(2),sprintf(' (%.1f)[55 35]',y1(2)))
text(x1(3),y1(3),sprintf(' (%.1f)[35 35]',y1(3)))
i= 4
x2=(ones(1,3)+1);
y2=A(:,(i:(i+2)))
hold on
scatter(x2,y2,'filled','r')
xtics=[0:1:4];
xticlab={'' '20sec' '35sec' '50sec' ''};
set(gca,'XTick',xtics,'XTickLabel',xticlab,'Fontsize', 10)
text(x2(1),y2(1),sprintf(' (%.1f)[55 55]',y2(1)))
text(x2(2),y2(2),sprintf(' (%.1f)[55 35]',y2(2)))
text(x2(3),y2(3),sprintf(' (%.1f)[35 35]',y2(3)))
i= 7
x3=(ones(1,3)+2);
y3=A(:,(i:(i+2)))
hold on
scatter(x3,y3,'filled','r')
xtics=[0:1:4];
xticlab={'' '20sec' '35sec' '50sec' ''};
set(gca,'XTick',xtics,'XTickLabel',xticlab,'Fontsize', 10)
text(x3(1),y3(1),sprintf(' (%.1f)[55 55]',y3(1)))
text(x3(2),y3(2),sprintf(' (%.1f)[55 35]',y3(2)))
text(x3(3),y3(3),sprintf(' (%.1f)[35 35]',y3(3)))
i= 10
x4=(ones(1,3));
y4=A(:,(i:(i+2)))
hold on
scatter(x4,y4,'filled','b')
xtics=[0:1:4];
xticlab={'' '20sec' '35sec' '50sec' ''};
set(gca,'XTick',xtics,'XTickLabel',xticlab,'Fontsize', 10)
text(x4(1),y4(1),sprintf(' (%.1f)[55 55]',y4(1)))
text(x4(2),y4(2),sprintf(' (%.1f)[55 35]',y4(2)))
text(x4(3),y4(3),sprintf(' (%.1f)[35 35]',y4(3)))
i= 13
x5=(ones(1,3)+1);
y5=A(:,(i:(i+2)))
hold on
scatter(x5,y5,'filled','b')
xtics=[0:1:4];
xticlab={'' '20sec' '35sec' '50sec' ''};
set(gca,'XTick',xtics,'XTickLabel',xticlab,'Fontsize', 10)
text(x5(1),y5(1),sprintf(' (%.1f)[55 55]',y5(1)))
text(x5(2),y5(2),sprintf(' (%.1f)[55 35]',y5(2)))
text(x5(3),y5(3),sprintf(' (%.1f)[35 35]',y5(3)))
i= 16
x6=(ones(1,3)+2);
y6=A(:,(i:(i+2)))
scatter(x6,y6,'filled','b')
hold on
xtics=[0:1:4];
xticlab={'' '20sec' '35sec' '50sec' ''};
set(gca,'XTick',xtics,'XTickLabel',xticlab,'Fontsize', 10)
text(x6(1),y6(1),sprintf(' (%.1f)[55 55]',y6(1)))
text(x6(2),y6(2),sprintf(' (%.1f)[55 35]',y6(2)))
text(x6(3),y6(3),sprintf(' (%.1f)[35 35]',y6(3)))
i= 19
x7=(ones(1,3));
y7=A(:,(i:(i+2)))
hold on
scatter(x7,y7,'filled','k')
xtics=[0:1:4];
xticlab={'' '20sec' '35sec' '50sec' ''};
set(gca,'XTick',xtics,'XTickLabel',xticlab,'Fontsize', 10)
text(x7(1),y7(1),sprintf(' (%.1f)[55 55]',y7(1)))
text(x7(2),y7(2),sprintf(' (%.1f)[55 35]',y7(2)))
text(x7(3),y7(3),sprintf(' (%.1f)[35 35]',y7(3)))
i= 22
x8=(ones(1,3)+1);
y8=A(:,(i:(i+2)))
hold on
scatter(x8,y8,'filled','k')
xtics=[0:1:4];
xticlab={'' '20sec' '35sec' '50sec' ''};
set(gca,'XTick',xtics,'XTickLabel',xticlab,'Fontsize', 10)
text(x8(1),y8(1),sprintf(' (%.1f)[55 55]',y8(1)))
text(x8(2),y8(2),sprintf(' (%.1f)[55 35]',y8(2)))
text(x8(3),y8(3),sprintf(' (%.1f)[35 35]',y8(3)))
i= 25
x9=(ones(1,3)+2);
y9=A(:,(i:(i+2)))
hold on
scatter(x9,y9,'filled','k')
xtics=[0:1:4];
xticlab={'' '20sec' '35sec' '50sec' ''};
set(gca,'XTick',xtics,'XTickLabel',xticlab,'Fontsize', 10)
text(x9(1),y9(1),sprintf(' (%.1f)[55 55]',y9(1)))
text(x9(2),y9(2),sprintf(' (%.1f)[55 35]',y9(2)))
text(x9(3),y9(3),sprintf(' (%.1f)[35 35]',y9(3)))
xlim([0 4])
ylabel('CO emissions [mg]')
title ('CO emission for 25 sec after catalyst 1')
legend('2 kW' ,'' ,'' ,'3 kW' ,'','','4 kW')
  6 comentarios
Rik
Rik el 11 de Feb. de 2022
They all depend on A directly: A(:,i:(i+2)). There is nothing in the code that suggests anything is different. You only use numbered variables, that is the only difference I see.
Apart from the line that defines the value of i and the numbered variables, what is the difference?
Below I have interleave two of the examples you mention. Where exactly is the difference?
i= 1
i= 10
x1=ones(1,3);
x4=(ones(1,3));
y1=A(:,(i:(i+2)))
y4=A(:,(i:(i+2)))
hold on
hold on
a=scatter(x1,y1,'filled','r')
scatter(x4,y4,'filled','b')
xtics=[0:1:4];
xtics=[0:1:4];
xticlab={'' '20sec' '35sec' '50sec' ''};
xticlab={'' '20sec' '35sec' '50sec' ''};
set(gca,'XTick',xtics,'XTickLabel',xticlab,'Fontsize', 10)
set(gca,'XTick',xtics,'XTickLabel',xticlab,'Fontsize', 10)
text(x1(1),y1(1),sprintf(' (%.1f)[55 55]',y1(1)))
text(x4(1),y4(1),sprintf(' (%.1f)[55 55]',y4(1)))
text(x1(2),y1(2),sprintf(' (%.1f)[55 35]',y1(2)))
text(x4(2),y4(2),sprintf(' (%.1f)[55 35]',y4(2)))
text(x1(3),y1(3),sprintf(' (%.1f)[35 35]',y1(3)))
text(x4(3),y4(3),sprintf(' (%.1f)[35 35]',y4(3)))
Prasad Joshi
Prasad Joshi el 11 de Feb. de 2022
Actually I am not that much proficient in Programming a beginner .....I am just seeing from online stuffs and developing code ...can you suggest how can I add for loop to this case ...Thank you in advance

Iniciar sesión para comentar.

Respuestas (1)

Prasad Joshi
Prasad Joshi el 11 de Feb. de 2022
Just in cases anyone requiried add duplicate entries to code ...it work for me
hold on
h1 = scatter(-10,-10, 'r,'filled', 'DisplayName', ' 2kW');
h2 = scatter(-10,-10, 'b','filled', 'DisplayName', '3 kW');
h3 = scatter(-10,-10, 'k','filled', 'DisplayName', '4 kW');
% duplicating the plot
xlim([0 10] ) % taking positive values
legend([h1(1) h2(1) h3(1)])
  2 comentarios
Rik
Rik el 11 de Feb. de 2022
Note that this is exactly what I suggested in my initial comment.
Prasad Joshi
Prasad Joshi el 11 de Feb. de 2022
ya ...Thank you RIK for you help ......

Iniciar sesión para comentar.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by