Re-order legend but mismatch colour?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
wesleynotwise
el 27 de Mayo de 2017
Editada: wesleynotwise
el 30 de Mayo de 2017
I want to differentiate my data in a scattered plot based on the source of data, e.g. USA, Italy, UK and France. I realised that the order they appear in the legend is in alphabetical order (default setting?), that is, France, Italy, UK and USA. When I changed their order in the legend, the data did not match with the colour. Any ideas?
f1 = gscatter(x, y, country, 'ygbr'); %by default, the output of this is France(y), Italy(g), UK (b), USA(r)
get(legend(), 'String');
neworder = [3 4 2 1]; % I want it to appear as: UK(b), USA(r), Italy(g), France(y)
legend([f1], labels (neworder)); % the output is: UK(y), USA(g), Italy(b), France(r)
0 comentarios
Respuesta aceptada
the cyclist
el 28 de Mayo de 2017
Editada: the cyclist
el 28 de Mayo de 2017
You need to reorder the handle as well. Something like this ...
legend(f1(neworder), labels(neworder))
Here is an example adapted from the documentation for gscatter:
load discrim
figure
f1 = gscatter(ratings(:,1),ratings(:,2),group,'br','xo');
legendText = {'g1','g2'};
newOrder = [2 1];
legend(f1(newOrder),legendText(newOrder))
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Distribution Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!