changing the style in a loop with hold all...

36 ビュー (過去 30 日間)
Doron
Doron 2012 年 2 月 21 日
回答済み: Bruno Melo 2019 年 6 月 20 日
In a loop, "hold all" successively changes the colour of the lines in a plot...
But, this is not so useful to me because:
1. It goes back to a blue line after 7 plots.
2. I am going to be printing in black and white (or grey).
I would much rather Matlab rotated between the line-styles (-, --, :, ., etc...). Is there any way to change the style, as opposed the colour?
Note: I do not want a "just create an array of strings for the styles" solution, I am aware of this solution, and it feels wrong.
Thanks
D Howard
  1 件のコメント
Ali
Ali 2017 年 10 月 29 日
if true
--------------------------------------------------- code start
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
<</matlabcentral/answers/uploaded_files/92608/untitled.bmp>>

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

採用された回答

Kevin Holst
Kevin Holst 2012 年 2 月 21 日
I found a solution to this, which I just put in your previous question.
If you set the default colororder and linestyleorder, I think it'll do what you want.
The commands are:
set(0,'defaultaxescolororder',[0 0 0; 0.5 0.5 0.5]) %black and gray
set(0,'defaultaxeslinestyleorder',{'-*',':','o'}) %or whatever you want
  7 件のコメント
Patrick Kalita
Patrick Kalita 2012 年 2 月 22 日
Without restarting MATLAB you can undo a default set like this:
% set a default:
set(0, 'DefaultAxesColorOrder', [0 0 0]);
% undo it:
set(0, 'DefaultAxesColorOrder', 'remove')
Kevin Holst
Kevin Holst 2012 年 2 月 23 日
Thanks for the info, Patrick, that's definitely good to know.

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

その他の回答 (4 件)

Jarrod Rivituso
Jarrod Rivituso 2012 年 2 月 21 日
Ok I understand your remark about it "feeling wrong" so please don't hate me for suggesting this... However, a little-known trick is to use the set function to get a list of all possible options for things like markers or line styles. Example
ph = plot(1:10)
allLineStyles = set(ph,'LineStyle')
allMarkers = set(ph,'Marker')
You could then keep a counter and loop through a combination of those two properties. This way you aren't hard-coding a list of strings. It's still not as clean a solution as something like hold.
I'm not sure if there is a more elegant solution.
  1 件のコメント
Sean de Wolski
Sean de Wolski 2012 年 2 月 22 日
+1 - Awesome!

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


Patrick Kalita
Patrick Kalita 2012 年 2 月 21 日
This is the same basic idea as Kevin Holst's answer, but you don't need to set the default LineStyleOrder for all axes. You can just set it for the one you're interested in:
% Set axes properties
set(gca, 'ColorOrder', [0 0 0; 0.5 0.5 0.5]); % just black and grey
set(gca, 'LineStyleOrder', {'-', ':', '--', '-.'}); % different line styles
% Call hold so that the first plot doesn't affect the properties you just set
hold all
% Now make some plots
plot( rand( 1, 10 ) );
plot( rand( 1, 10 ) );
plot( rand( 1, 10 ) );
plot( rand( 1, 10 ) );
plot( rand( 1, 10 ) );
plot( rand( 1, 10 ) );
Also note that MATLAB uses each color in the ColorOrder with the first line style in LineStyleOrder, then it uses each color with the second style in LineStyleOrder, etc.
  1 件のコメント
Hems
Hems 2018 年 2 月 8 日
Is there any way to modify the code such that Matlab uses each color in the ColorOrder with all the line styles in LineStyleOrder and then jumps to the next color?

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


Edward Byers
Edward Byers 2013 年 5 月 23 日
I have been battling with this exact problem and in finding your question, found the answer, and suggest a similar solution that you may like.
mrk={'o','s','*','v','+','^'}; %These are the markers
for n=1:6
hold all %The position of hold all BEFORE 'set(gca)' and 'plot' is important
set(gca,'LineStyle',mrk(n)) % mrk(n) will cycle through markers in your loop
plot(pk3x4(:,n));
end

Bruno Melo
Bruno Melo 2019 年 6 月 20 日
I've also read all forum questions concerning this issue and got around by using this function made by Sébastien Martin.
Hope it helps you.
https://www.mathworks.com/matlabcentral/fileexchange/52091-plot-with-linestyles-and-markers#feedbacks

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by