Why is my subplot legend empty when I run my script using MATLAB 2021b but it is okay when run with R2020b?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2022-8-17
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!