Legend entries all same color in Matlab 2015b

I just updated to Matlab 2015b, and the frustration has already begun.
I am making a simple scatter plot with multiple data sets. Each data set has a different color, but the legend shows points all in the same color. Example code showing problem below: (ONLY IN 2015b)
---------------
x = 1:1:100;
y1 = rand(1,100);
y2 = rand(1,100);
y3 = rand(1,100);
figure;
scatter(x,y1);
hold on;
scatter(x,y2,'*');
scatter(x,y3);
legend('random 1','random 2','random 3') ;
---------------
The different symbol choice on 'random 2' illustrates that the problem is only with color, and not with referencing the same handle for each.
Help much appreciated!
Maddie

4 件のコメント

Star Strider
Star Strider 2015 年 9 月 14 日
Definitely a bug. Nothing I tried (specifying colours and markers, returning handles and sending them to legend as arguments) alters what you saw. Since you discovered it, report it as a bug to TMW Tech Support.
the cyclist
the cyclist 2015 年 9 月 14 日
Agree on bug report suggestion. This code works properly for me in 2015a, and not 2015b.
Talfan Evans
Talfan Evans 2016 年 7 月 4 日
Also found this bug. Easy to use the plot command but specify the marker type, i.e:
scatter(x,y,'r')
produces the same output as:
plot(x,y,'or')
The bug doesn't seem to affect the plot command.
joebob
joebob 2017 年 2 月 16 日
Hello, found a way to show the color in the legend by forcing the `MarkerFaceColor` property:
h = scatter(x_data, y_data, area_data, 'green', 'filled', 'MarkerFaceColor', 'green');

サインインしてコメントする。

 採用された回答

Mike Garrity
Mike Garrity 2015 年 9 月 15 日

2 投票

That sounds like bug 1283854. There's a patch and some workarounds at that link.

2 件のコメント

Madison Smith
Madison Smith 2015 年 9 月 15 日
That is exactly it. Thanks so much!
lis coffey
lis coffey 2016 年 7 月 4 日
i guess the problem is only with color, and not with referencing the same handle for each. Thanks \ Qwikfix \

サインインしてコメントする。

その他の回答 (4 件)

Jacob Kamminga
Jacob Kamminga 2016 年 6 月 28 日

3 投票

From the bugreport, Use this workaround when the points within each scatter plot are different colors:
Call the legend function with two or more output arguments:
s1 = scatter(1:10,1:10,[],1:10);
hold on
s2 = scatter(2:11,1:10,[],26:35);
[h, ~] = legend('show');

1 件のコメント

Alexandre Damião
Alexandre Damião 2017 年 1 月 8 日
Very nice! This worked perfectly for me. Thanks!

サインインしてコメントする。

Tony L.
Tony L. 2015 年 9 月 15 日

0 投票

There must be a cleaner way to do this than the below, but gscatter seems to do the right thing:
x = 1:1:100;
y1 = rand(1,100);
y2 = rand(1,100);
y3 = rand(1,100);
g1 = repmat(1,length(y1),1);
g2 = repmat(2,length(y2),1);
g3 = repmat(3,length(y3),1);
ds = [x', y1', g1; x', y2', g2; x', y3', g3];
figure;
gscatter(ds(:,1), ds(:,2), ds(:,3));
legend('random 1','random 2','random 3') ;
SHR
SHR 2016 年 3 月 1 日

0 投票

I have a similar issue. My data set is a table with multiple variables over time associated with specific locations. I wanted to graph all variables (y axis) over time on one scatter plot only for one location. Thus I converted the dates to DateNumebers and restricted the variables by location e.g., Y1-Znppm(SiteCat=='location_x'. The legend has the same symbol color. Is there an easier way to circumvent the bug?

1 件のコメント

Walter Roberson
Walter Roberson 2016 年 3 月 2 日
Are you using R2015a? If so then apply the patch Mike indicated.

サインインしてコメントする。

Amir Mohammad Alizadeh
Amir Mohammad Alizadeh 2016 年 5 月 25 日

0 投票

and the bloody doesn't work. MATLAB is horrible

1 件のコメント

Walter Roberson
Walter Roberson 2017 年 1 月 9 日
Which MATLAB version are you using? Did you apply the patch?

サインインしてコメントする。

カテゴリ

製品

質問済み:

2015 年 9 月 14 日

コメント済み:

2017 年 2 月 16 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by