I want to hold legends from different callback on same plot.

2 ビュー (過去 30 日間)
Sandy Baha
Sandy Baha 2016 年 8 月 24 日
コメント済み: Sandy Baha 2016 年 8 月 24 日
I have GUI with two PUSHBUTTONs to import the seperate excel files and numbers of CHECKBOX to plot the respective graphs on * same figure* to compare the results. When i click one checkbox it plot the graph with its legend. When i click other checkbox it also plot the graph on same figure but previous legend vanishes and it overrides new legend. I want to keep old legend also to compare the graphs. Please suggest...
if true
function AFR_Test_Callback(hObject, eventdata, handles)
% hObject handle to AFR_Test (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of AFR_Test
handles = guidata(hObject);
a2 = handles.a;
AFR2 = handles.AFR;
LGD2 = handles.LGD1
if get(handles.AFR_Test,'Value')
figure(1)
hold on
handles.h1 = plot(a2,AFR2,'*--')
handles.rt = legend(LGD2,'Location','southwest','FontSize',8,'FontWeight','bold')
title('AFR')
xlabel('Speed (RPM)','FontSize',8,'FontWeight','bold');
ylabel('AFR','FontSize',8,'FontWeight','bold');
grid on;
hold on;
guidata(hObject,handles);
else
if ~isempty(handles.h1)
set(handles.h1,'Visible','off');
delete (handles.rt);
end
end
guidata(hObject,handles);
end
function AFR_Sim_Callback(hObject, eventdata, handles)
% hObject handle to AFR_Sim (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of AFR_Sim
handles = guidata(hObject);
a2 = handles.a;
AFR_2 = handles.AFR_1;
TEST2 = handles.TEST1
if get(handles.AFR_Sim,'Value')
figure(1)
hold on
handles.h1 = plot(a2,AFR2,'*--')
handles.rt = legend(TEST2,'Location','southwest','FontSize',8,'FontWeight','bold')
title('AFR')
xlabel('Speed (RPM)','FontSize',8,'FontWeight','bold');
ylabel('AFR','FontSize',8,'FontWeight','bold');
grid on;
hold on;
guidata(hObject,handles);
else
if ~isempty(handles.h1)
set(handles.h1,'Visible','off');
delete (handles.rt);
end
end

回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2016 年 8 月 24 日
It seems that you might get what you want with the legendflex file exchange submission - it allows multiple legends to be added to an axis, seems like what you want to do. It might require some additional adaptations of your code but you'll figure it out.
  1 件のコメント
Sandy Baha
Sandy Baha 2016 年 8 月 24 日
Appreciate to your quick answer. I have used legendflex but it still overriding the legends.

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

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by