creating line plot with different marker color and legends

조회 수: 1 (최근 30일)
Hi,
I have data stored in two arrays as follows.
A = [10.15 , 10.92, 11.81,12.83]
B = [3.92, 9.18, 14.87, 18.14].
I am creating plot using the below shown script. Here, I would like to create line plot with different marker colors and also the legends. I can able to generate different marker color and legends, but not with the line. Is there any way to create line plot with this ??
plot (A (1,1), B(1,1), '*','color', 'b','markersize',20);
hold on
plot (A (2,1), B(2,1), '*','color', 'r','markersize',20);
hold on
plot (A (3,1), B(3,1), '*','color', 'g','markersize',20);
hold on
plot (A (4,1), B(4,1), '*','color', 'm','markersize',20);
hold on
set (gca, 'Linewidth', 2);
set(gca, 'FontSize', 18)
set(gca,'TickLabelInterpreter','latex')
legend({'$\alpha_{a}=0$','$\alpha_{b}=0.1$','$\alpha_{c}=0.2$','$\alpha_{d}=0.3$'},'Interpreter','latex');

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 9월 18일
Your data is a row vector (1xn) but you are indexing it like it is a column vector (mx1). Since it is a vector, perhaps it is best to just use a single index to avoid this issue.
A = [10.15 , 10.92, 11.81,12.83];
B = [3.92, 9.18, 14.87, 18.14];
plot (A(1), B(1), '*','color', 'b','markersize',20);
hold on
plot (A(2), B(2), '*','color', 'r','markersize',20);
plot (A(3), B(3), '*','color', 'g','markersize',20);
plot (A(4), B(4), '*','color', 'm','markersize',20);
hold off
set(gca, 'Linewidth', 2,'FontSize', 18,'TickLabelInterpreter','latex')
legend({'$\alpha_{a}=0$','$\alpha_{b}=0.1$','$\alpha_{c}=0.2$','$\alpha_{d}=0.3$'},'Interpreter','latex');
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2021년 9월 18일
Currently your plot commands each plot a single point. You just need to add another plot command for all the data together.
A = [10.15 , 10.92, 11.81,12.83];
B = [3.92, 9.18, 14.87, 18.14];
plot(A(1), B(1), '*','color', 'b','markersize',20);
hold on
plot(A(2), B(2), '*','color', 'r','markersize',20);
plot(A(3), B(3), '*','color', 'g','markersize',20);
plot(A(4), B(4), '*','color', 'm','markersize',20);
% Now plot all the data
plot(A,B,'k','Linewidth',2)
hold off
set(gca, 'Linewidth', 2,'FontSize', 18,'TickLabelInterpreter','latex')
legend({'$\alpha_{a}=0$','$\alpha_{b}=0.1$','$\alpha_{c}=0.2$','$\alpha_{d}=0.3$'},'Interpreter','latex','Location','best');
Turbulence Analysis
Turbulence Analysis 2021년 9월 18일
Perfect !! Thanks a lot ..

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by