Plotting a legend without displaying data on UIAxes
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mohammad Shahbazy
am 26 Sep. 2022
Kommentiert: Mohammad Shahbazy
am 26 Sep. 2022
Hi all,
I want to show a legend without showing the plot data on the app.UIAxes in App Designer. I written the following code but at the end it shows a legend box as an disabled legend (attached figure). How can I correct my code?
I would be apprciated if you kindly guide me.
Many thanks,
Moh
colororder = {'r','g','b','c','m'};
x = rand(100,5);
label = cellstr(num2str([1:1:size(x,2)]', 'cluster%d'));
for i=1:1:size(x,2)
axis(app.UIAxes,'off');
set(app.UIAxes,'visible','off');
f = plot(app.UIAxes,x(:,i),'Color',colororder{i});
hold(app.UIAxes,'on');set(f,'visible','off');
end
hold(app.UIAxes,'on');
set(app.UIAxes,'visible','off');
axis(app.UIAxes,'off');
hold(app.UIAxes,'on');
legend(app.UIAxes,label,'AutoUpdate','off');
2 Kommentare
Walter Roberson
am 26 Sep. 2022
What legend would you like displayed when all of your lines are invisible?
Akzeptierte Antwort
Chris
am 26 Sep. 2022
Bearbeitet: Chris
am 26 Sep. 2022
colororder = {'r','g','b','c','m'};
x = rand(100,5);
label = cellstr(num2str([1:1:size(x,2)]', 'cluster%d'));
% Plot a point but don't grab its handle
plot(app.UIAxes,0,0);
hold(app.UIAxes,'on')
for i=1:1:size(x,2)
% Get handles to the other plots, which are nan
f(i) = plot(app.UIAxes,NaN,NaN,'Color',colororder{i});
end
axis(app.UIAxes,'off');
legend(f,label,'AutoUpdate','off');
Adapted from answers here
Weitere Antworten (1)
Simon Chan
am 26 Sep. 2022
Try this if you would like to show the figure and legend without showing the data.
Set the 'LineStyle' to 'none' to hide the lines.
colororder = {'r','g','b','c','m'};
x = rand(100,5);
label = cellstr(num2str([1:1:size(x,2)]', 'cluster%d'));
fig = figure;
ax = gca;
for i=1:1:size(x,2)
f = plot(ax,x(:,i),'Color',colororder{i},'LineStyle','none'); % Use LineStyle = 'none'
hold(ax,'on');
end
hold(ax,'off');
legend(ax,label,'AutoUpdate','off');
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!