Why is my subplot legend empty when I run my script using MATLAB 2021b but it is okay when run with R2020b?

4 visualizzazioni (ultimi 30 giorni)
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);

Risposta accettata

Walter Roberson
Walter Roberson il 17 Ago 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.
  1 Commento
John Lauria
John Lauria il 17 Ago 2022
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

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by