Borrar filtros
Borrar filtros

How to change Legend Bar Color's Object?

6 visualizaciones (últimos 30 días)
Tyann Hardyn
Tyann Hardyn el 9 de Abr. de 2022
Comentada: Frantisek Gaspar el 15 de Abr. de 2022
Dear Community,
i wanna ask something that could be simple to answer... I just curious about how to change Object's Color in Legend like this :
Iam using bar function with "flat" facecolor and then i can manage the color of bar in every data, but i still cannot change the color of that rectangle object (which re still depend on the very first data bar color) to become other color. Would everyone lend me a hand to give some clues about how to manage it with some codes maybe? Thank you so much everyone....

Respuesta aceptada

Frantisek Gaspar
Frantisek Gaspar el 13 de Abr. de 2022
The color depends on the object the legend entry belongs to. The simplest way to change it is to create invisible graphical object with desired color and create new legend. To change the color manualy in existing legend you have to use undocumented legend properties: https://undocumentedmatlab.com/articles/plot-legend-customization
  2 comentarios
Tyann Hardyn
Tyann Hardyn el 15 de Abr. de 2022
How to create an invisible graphical objects, Sir? Would you mind to give me 1 example of code, perhaps?
Frantisek Gaspar
Frantisek Gaspar el 15 de Abr. de 2022
Invisible grafical objects can be usualy created with nan as input:
figure
hold on
h1 = bar(5);
h1.FaceColor = "red";
h2 = bar(nan);
h2.FaceColor = "blue";
h2.DisplayName = "Fake Legend";
legend(h2)

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by