File Exchange

image thumbnail

PLOTA

version 1.0 (1.09 KB) by

PLOTA plots each new plot using other color.

0 Downloads

Updated

No License

PLOTA is the same as standard PLOT function, BUT it plots each new plot using other color ( making 'hold on' automatically and cycling through the colors in the order specified by the current axes ColorOrder property )

EXAMPLE:
figure;
plota(randn(1,100));
plota(randn(1,100));
plota(randn(1,100));
legend('First call to plota', 'Second call to plota', 'Third call to plota')

Comments and Ratings (7)

daniloz

Sorry, I made a mistake on my previous comment (is it possible to edit/delete it)... The function should be:

ca = get(get(0,'CurrentFigure'),'CurrentAxes');
if isempty( ca )
ordi0 = 0;
else
ordi0 = length(get(ca,'Children'));
CurrentHold = get( gca, 'NextPlot');
set( gca, 'NextPlot', 'add' );
end
hp = plot( varargin{:} );
ColOrd = get(gca, 'ColorOrder');
children = get(gca,'Children');
ordi = length(children);
ord = mod((ordi0+1:ordi)-1, size(ColOrd,1));
cc = 0;
for ii = (ordi - ordi0): -1 : 1
cc = cc + 1;
set(children(ii), 'Color', ColOrd(((ordi0+cc)<=size(ColOrd,1))*(ordi0+cc) + ((ordi0+cc)>size(ColOrd,1))*(ord(cc)+1), :));
end
if ordi0 == 0,
set( gca, 'NextPlot', 'replace');
else
set( gca, 'NextPlot', CurrentHold);
end

daniloz

Thank you - very helpful tool !!!!

Just a comment: sine I often use handles to plots, I've change the function definition to:

function hp = plota(varargin)

IVAN

IVAN (view profile)

This is perfect! I´m very grateful for this function

Rob Campbell

Rob Campbell (view profile)

If your x axes have the same lengths then you don't need a new function. Just:
plot(randn(3,100)')

Also see:
http://blogs.mathworks.com/pick/2008/08/15/colors-for-your-multi-line-plots/

Yonggun Jun

This is what I was looking for!!

Natanya Black

Thank you - that was very helpful!!!

David Sekyere

MATLAB Release
MATLAB 6.5.1 (R13SP1)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today