Why is my subplot legend empty when I run my script using MATLAB 2021b but it is okay when run with R2020b?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
John Lauria
am 16 Aug. 2022
Kommentiert: John Lauria
am 17 Aug. 2022
subplot(1,2,1);
% bring up legend outside of plot area and move to desired position
legend_handle = legend('','','','','','','','');
set(legend_handle,'Location','EastOutside'); %% % <<<<< The legend appears here for R2020b but NOT for R2021b
set(legend_handle,'Orientation','vertical');
set(legend_handle,'FontSize',8);
% move subplot to the left in figure and resize width
pos = get(gca,'Position'); % natural positions for subplot 0.13, 0.11, 0.2597, 0.815
set(gca,'Position',pos); % move subplot to the left in figure and resize width
Legend_Sting = {'Travel Range','Retract Stops','Insert Stops','Offsets','SW Retract Limit','SW Insert Limit','Max Retract Limit','Min Insert Limit',''};
% move the legend position so it is to the right of plot near bottom of figure
set(legend_handle,'String',Legend_Sting);
Legend_Position = [0.52,0.08,0.2,0.2];
set(legend_handle,'Position',Legend_Position);
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 17 Aug. 2022
legend_handle = legend('','','','','','','','');
At some point, legend() changed so that specifying '' as the legend string caused the legend to be turned off for that entry, rather than creating a legend entry that happened to have a corresponding character vector.
Thus you are turning off the legend for 8 entries -- so those entries do not exist for you to manipulate the string property.
When I test your code in R2022a, an empty legend box is generated.
Weitere Antworten (0)
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!