How to avoid patch color in legend?

2 次查看(过去 30 天)
Sorry , i can to send only you a little piece of code..
here "
plot(Ax_Eq,XDates(xx_:end),TE_strum(xx_:end,i)','Color',"black",'LineWidth',width_arr(i));
(SECOND PLOT)
i plot with another color the the last part of equity
Problem is the legend:
Some are colored black in the legend.. Instead I only want the legend like those of the initial plot (FIRST PLOT)
("
plot(Ax_Eq,XDates,TE_strum(:,i)','DisplayName',STR_name{i},'Color',col(i,:),'LineWidth',width_arr(i));
")
for i=1:c
if STR_type(i)==1 %%se sono aggregate
SumCTR_color(b(i),:)= col(i,:); %%cosi nel draw del SumCTR_strum gli do il colore uguale
end
%%********* FIRST PLOT ***********************
plot(Ax_Eq,XDates,TE_strum(:,i)','DisplayName',STR_name{i},'Color',col(i,:),'LineWidth',width_arr(i));
%%**********************************************
text(Ax_Eq,r-2,TE_strum(end,i),strcat({' '},num2str(i)),'Color',col(i,:),'Interpreter','none');
if app.OOScolorCheckBox.Value %%mi colora di nero da dove inizia solo l'OOS (se ci sono 4 sistemi prende l'OOS piu' recente!!)!
oos=datetime(string({app.Sis.OOS}),'Format','dd/MM/yyyy');
xx=cell2mat(app.Seraf_T(:,3));
[~,xx_]=find(max(oos(xx))==XDates); %%max perche prendo l'OOS piu' recente!
%%********* SECOND PLOT ***********************
plot(Ax_Eq,XDates(xx_:end),TE_strum(xx_:end,i)','Color',"black",'LineWidth',width_arr(i));
%%***************************************
end
%%******************************
end
%%*************************
nm=Convert_ArrayDouble_StringDollar_Struct(TE_strum(end,:)',0);
tm=compose("%s", Ntrad_strum');
leg=strcat(string(1:c)',{' - '},string(STR_name),"==>",nm," ",tm);
legend(Ax_Eq,leg,'Location','northwest','Interpreter','none','Box','off');

采纳的回答

Voss
Voss 2024-5-3
编辑:Voss 2024-5-3
In the call to legend, you can specify which lines (or whatever) you want included.
Here it's legend_lines:
legend_lines = gobjects(1,c);
for i=1:c
if STR_type(i)==1 %%se sono aggregate
SumCTR_color(b(i),:)= col(i,:); %%cosi nel draw del SumCTR_strum gli do il colore uguale
end
%%********* FIRST PLOT ***********************
legend_lines(i) = plot(Ax_Eq,XDates,TE_strum(:,i)','DisplayName',STR_name{i},'Color',col(i,:),'LineWidth',width_arr(i));
%%**********************************************
text(Ax_Eq,r-2,TE_strum(end,i),strcat({' '},num2str(i)),'Color',col(i,:),'Interpreter','none');
if app.OOScolorCheckBox.Value %%mi colora di nero da dove inizia solo l'OOS (se ci sono 4 sistemi prende l'OOS piu' recente!!)!
oos=datetime(string({app.Sis.OOS}),'Format','dd/MM/yyyy');
xx=cell2mat(app.Seraf_T(:,3));
[~,xx_]=find(max(oos(xx))==XDates); %%max perche prendo l'OOS piu' recente!
%%********* SECOND PLOT ***********************
plot(Ax_Eq,XDates(xx_:end),TE_strum(xx_:end,i)','Color',"black",'LineWidth',width_arr(i));
%%***************************************
end
%%******************************
end
%%*************************
nm=Convert_ArrayDouble_StringDollar_Struct(TE_strum(end,:)',0);
tm=compose("%s", Ntrad_strum');
leg=strcat(string(1:c)',{' - '},string(STR_name),"==>",nm," ",tm);
legend(Ax_Eq,legend_lines,leg,'Location','northwest','Interpreter','none','Box','off');

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by