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);

采纳的回答

Walter Roberson
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.
  1 个评论
John Lauria
John Lauria 2022-8-17
Thank you Walter. I replaced the empty strings which at this point were only placeholders with some real ascii characters and that fixed my problem!
legend_handle = legend('a','b','c','d','e','f','g','h'); % placeholders

请先登录,再进行评论。

更多回答(0 个)

类别

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

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by