[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Legend in scatter plot
From: |
Ben Abbott |
Subject: |
Re: Legend in scatter plot |
Date: |
Thu, 02 Jun 2011 14:37:22 -0400 |
On Jun 2, 2011, at 11:46 AM, Daniel Arteaga wrote:
> Al 02/06/11 14:10, En/na Ben Abbott ha escrit:
>
>>> How can I print a legend in a scatter plot with different colours? A
>>> minimal example:
>>>
>>> color = [0;0.5;1];
>>> scatter([0.15, 1.15 -1.15],[2.15 0 1.15],25,color);
>>> legend({"a";"b";"c"});
>>>
>>> The legend does not appear.
>>>
>>> Tested in Octave 3.4.0 compiled from source in Ubuntu 11.04 64 bits.
>>>
>>> Any help will be appreciated. Thanks,
>>>
>>> Daniel
>>
>> Looks like a bug.
>>
>> The code below does work in Matlab.
>>
>> color = [0; 0.5; 1];
>> h = scatter ([0.15, 1.15, -1.15],[2.15, 0, 1.15], 25, color);
>> legend (get (h, 'children'), {'a', 'b', 'c'});
>>
>> Using your original syntax, the legend entries are associated with the
>> scatter object (an hggroup). So only one entry should show. However, this
>> does not work for the gnuplot backend. If you switch to FLTK then you'll see
>> the legend, but it is not rendered correctly.
>>
>> graphics_toolkit fltk
>> color = [0; 0.5; 1];
>> h = scatter ([0.15, 1.15, -1.15],[2.15, 0, 1.15], 25, color);
>> legend (get (h, 'children'), {'a', 'b', 'c'});
>>
>> I've filed a bug report.
>>
>> https://savannah.gnu.org/bugs/index.php?33463
>
> Thank you for the bug report. Unfortunately I cannot test the fltk behaviour
> since apparently I haven't enabled this graphics backend at compilation time.
>
> Any possible workaround in the meanwhile will be appreciated.
Does the script below suit your needs?
color = [0; 0.5; 1];
x = [0.15, 1.15, -1.15];
x = mat2cell (x, 1, ones (size (x)));
y = [2.15, 0, 1.15];
y = mat2cell (y, 1, ones (size (y)));
m = repmat ({"s"}, size (x));
h = plot ([x;y;m]{:});
legend ({"a", "b", "c"});
map = colormap ();
for n = 1:numel(h)
idx = round (interp1 ([0, 1], [1, size(map,1)], color(n)));
set (h(n), "color", map(idx,:))
end
Ben