plotting in different colors with different linestyles or markers

조회 수: 29 (최근 30일)
mohsen
mohsen 2013년 6월 7일
답변: emami.m 2021년 1월 14일
I want to plot a multiple graf of varing a function in one plot with different color with different markers or different linestyle. I searched for it since 2 weeks ago. I found some method but they didn't help my request.
% mmm=['r';'b';'k';'m';'g'];
mmm=[1 0 0; 0 1 0;0 0 1;0 0 0;1 0 1];
kkk={':','--','-.','-','--'};
% set(gca(),'LineStyleOrder',kkk,'ColorOrder','default','NextPlot','replacechildren')
set(gca,'ColorOrder',mmm);
set(gca,'LineStyleOrder',kkk);
1- If i write the first line instead of 2nd, matlab can not plot with different colors, why?
2- At the 3rd line I define linestye, but matlab plots just with style of ':',why?(with commands in line 5 & 6)
Thanks.
  댓글 수: 1
Ali
Ali 2017년 10월 29일
if true
--------------------------------------------------- code start
This is an example for your case
Input is "Input_Data", two dimension matrix
Marker_Counter=1;
figure6=figure;
Markers = {'+','o','*','x','v','d','^','s','>','<'};
for i=1:10:size(Input_Data,1)
TPR=Input_Data(i:i+9,7);
FPR=Input_Data(i:i+9,8);
plot(FPR,TPR,strcat('-',Markers{Marker_Counter}));
Marker_Counter=Marker_Counter+1;
hold on
end
plot([0.5 1],[0.5 1],'--');
legend('Minpts = 100','Minpts = 200','Minpts = 300','Minpts = 400','Minpts = 500','Minpts = 600','Minpts = 700','Minpts = 800','Minpts = 900','Minpts = 1000','','Location','SouthEast');
xlabel('FPR or (1-Specificity)','FontSize',12,'FontWeight','bold'); ylabel('TPR or Spensitivity)','FontSize',12,'FontWeight','bold');
title('ROC Space');
close(gcf);
-------------------------------------------- code end
end
--------------------------------------- picture link preview

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

답변 (3개)

emami.m
emami.m 2021년 1월 14일
% Try this code. You can use it for all other line properties
h = plot(1:10,1:10,1:10,5:14,1:10,3:12,1:10,7:16); % Sample plot
kkk = {'+' ; 'o' ; '*' ; 'd'};
[h(:).Marker] = kkk{:};

Azzi Abdelmalek
Azzi Abdelmalek 2013년 6월 7일
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2013년 6월 7일
mohsen commented
there is another notation:
with command of hold all
the colour will be change automatically but variation of marker and line is dificult
Azzi Abdelmalek
Azzi Abdelmalek 2013년 6월 7일
mohsen commented
if I use just this command:
set(gca(),'LineStyleOrder',kkk,'ColorOrder',[0 0 0],'NextPlot','replacechildren')
each figure has different marker or line but with black color
it means that i can't plot with different color
is there any one help me?

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


Edmund Watson
Edmund Watson 2017년 10월 26일
I gave up in the end. I decided it was better just to do something like this
sizey = size(ydata);
style= {'-k','--b',':y'};
hold on
for k= 1:sizey(1)
plot(xdata,xten(k,:),style{k})
end

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by