is it possible to increment color and markers automatically for a plot in a loop?

26 ビュー (過去 30 日間)
MM
MM 2012 年 9 月 25 日
回答済み: Bruno Melo 2019 年 6 月 20 日
I want to use a loop to plot a series of datasets eg
for jj=1:numel(data)
plot(data{jj}(:,1),data{jj}(:,2),[Marker Color])
end
I'd like to know if there is a built-in function that I could use in my plot command so that Color and Marker are automatically incremented and that at the end of the day each dataset has a different marker/color.
I could do this
markers = {'+','o','*','.','x','s','d','^','v','>','<','p','h'}
and then access it this way:
markers{mod(i,numel(markers))+1}
and something similar for the colors but it's kind of ugly
any comments ?
  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

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

採用された回答

MM
MM 2012 年 9 月 25 日
In fact I think what really fits my need is
hold all

その他の回答 (3 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 25 日
編集済み: Azzi Abdelmalek 2012 年 9 月 25 日
color='rmbc'
markers = '+o*.x'
t=0:0.1:10;y=sin(t);
plot(t,y,[markers(2) color(3)])

Matt Fig
Matt Fig 2012 年 9 月 25 日
編集済み: Matt Fig 2012 年 9 月 25 日
You can do this:
set(0,'DefaultAxesLineStyleOrder',{'+','o','*','.','x','s','d','^','v','>','<','p','h'});
Then look:
figure
x = 0:.01:1;
hold all
for ii = 1:10
plot(x,x.^ii)
end
You should see that the marker changes every time the line color cycles through the colors.
  1 件のコメント
Kaiqi Fang
Kaiqi Fang 2015 年 3 月 4 日
It won't change the marker until the default color pool has been cycled through. From the following post, if you just use one color type,
set(0,'defaultaxescolororder',[0 0 0]);
, then you can let the marker change every time.

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


Bruno Melo
Bruno Melo 2019 年 6 月 20 日
Try this function, it worked out for me...
https://www.mathworks.com/matlabcentral/fileexchange/52091-plot-with-linestyles-and-markers#feedbacks

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by