Get access to the default LineStyleOrder and ColorOrder arrays in MATLAB -


quick "convenience" question matlab users. looping on plot command, passing different data plot each time. data happens generated function call, upon each iteration passed different parameter value. plot on same axis using 'hold' function. unfortunately doesn't auto cycle through available colororder and/or linestyleorder plot parameters, every line plotted has same style on every iteration.

for i=1:nlines     [x_data y_data]=get_xy_data(param1(i),param2(i))     plot(x_data,y_data) end 

every line plotted default blue line style. obvious solution generate front cell array of various line styles, , colors in:

line_styles={'-','--','-*'}; %...etc colors=colormap(jet(nlines)); 

then access each of on every iteration. want access default colors generated colororder, , default line cycling, comes linestyleorder. if try like:

get(gca,'linestyleorder') 

this returns styles used in axis (i've tested on axis defined 1 of styles, point is, doesn't give me possible linestyles). appreciated, thanks!

edit: let me more specific in looking for.

figure; hold on; i=1:nlines     [xdata, ydata]=get_data(p1(i),p2(i))  % call function return x,y data     plot(xdata,ydata) % on i=1, default blue line      % function tells matlab get/set next linestyle, color combination               nextstyle()        end 

if doesn't exist, wouldn't hard write it, thought i'd ask first before reinventing wheel.

you may interested in setting default properties of defaultaxeslinestyleorder , defaultaxescolororder.

the plots (style , color) first loop through newly defined colors , changed line style. in successive plot loop, using hold all "hold graph , current line color , line style subsequent plotting commands not reset colororder , linestyleorder" (see matlab doc). both examples produce identical results.

%default properties (line style , color)   set(0,'defaultaxeslinestyleorder',{'--','-',':'})   set(0,'defaultaxescolororder', summer(4))    figure('color','w');    %example plot 1 (concurrent plots)   subplot(1,2,1);   yvals = [1:50;1:50]   plot(yvals, 'linewidth', 2)   axis([1 2 0 size(yvals,2)+1 ]);   title('concurrent plot','fontsize',16);    %example plot 2 (iterative plots) subplot(1,2,2);   ii = 1:50       plot(yvals(:,ii), 'linewidth', 2);       hold all;   end   axis([1 2 0 size(yvals,2)+1 ]);   title('successive plot','fontsize',16);   

the results are

enter image description here

it looks @luis mendo not wrong!


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -