5.0

5.0 | 5 ratings Rate this file 6 Downloads (last 30 days) File Size: 1.09 KB File ID: #8767
image thumbnail

PLOTA

by

 

20 Oct 2005 (Updated )

PLOTA plots each new plot using other color.

| Watch this File

File Information
Description

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')

MATLAB release MATLAB 6.5.1 (R13SP1)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
24 Sep 2010 Danilo Zanatta

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

22 Jul 2010 Danilo Zanatta

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)

14 Jan 2010 IVAN

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

11 Jan 2010 Rob Campbell

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/

05 Mar 2008 Yonggun Jun

This is what I was looking for!!

18 Feb 2008 Natanya Black

Thank you - that was very helpful!!!

17 May 2006 David Sekyere  

Contact us