[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: legend in multiline plot
From: |
Ben Abbott |
Subject: |
Re: legend in multiline plot |
Date: |
Fri, 25 Feb 2011 09:07:20 -0500 |
On Feb 25, 2011, at 6:11 AM, Bernard Watts wrote:
> I'm trying to plot an n:8 matrix ("cadmium.csv") first column versus the 2 to
> 8 successively, with different colours for each line and a legend, using the
> script below.
> At work on an iMac G5 with MacOS 10.5.8 I get the legend and colours fine,
> allbeit behind the plotted lines. At home on an i3 Intel iMacwith Snow
> Leopard I get just one item which is the last "specname" with the first line
> colour, using the same script. Is there something wrong with my coding.
> I'm using the Octave 3.2.3 standalone app
>
> species = csvread ("cadmium.csv")
> specname = {"lCd"; "lCdOH"; "lCdOH2"; "lCdOH3"; "lCdOH4"; "lCd2OH4";
> "lCd4OH4"};
> for i = 2:8
> r=i/10
> g=1-i/10
> b=i/10
> (specname(i-1))
> plot (species ( :, 1), species( :, i), 'Linewidth', 2, 'Color', [r g b])
> legend (specname(i-1))
> hold ("on");
> endfor
The result you're getting on the Intel based Mac is consistent with Matlab, and
is how the developers sources currently is intended to work (I admit the older
Octave approach has some attraction for me).
A simple fix, for both 3.2.x and 3.4.x, is to delay the legend command until
after the loop ...
species = csvread ("cadmium.csv")
specname = {"lCd"; "lCdOH"; "lCdOH2"; "lCdOH3"; "lCdOH4"; "lCd2OH4"; "lCd4OH4"};
for i = 2:8
r=i/10
g=1-i/10
b=i/10
(specname(i-1))
plot (species ( :, 1), species( :, i), 'Linewidth', 2, 'Color', [r g
b])
hold ("on");
endfor
legend (specname)
Another possibility is to include the legend info in the plot command ...
species = csvread ("cadmium.csv")
specname = {"lCd"; "lCdOH"; "lCdOH2"; "lCdOH3"; "lCdOH4"; "lCd2OH4"; "lCd4OH4"};
for i = 2:8
r=i/10
g=1-i/10
b=i/10
(specname(i-1))
plot (species ( :, 1), species( :, i), sprintf (';%s;',
specname{i-1}), 'Linewidth', 2, 'Color', [r g b])
hold ("on");
endfor
I don't have a copy of your csv file, so I haven't tested the two solutions
above.
Ben