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');
0 个评论
采纳的回答
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
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');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!