Problems with legend in R2016b
古いコメントを表示
Why can I no longer add a plot with a legend in R2016b same way it used to be in previews versions?
During the migration to R2016b or R2017a, the script show some problems with legend function in the plot.
An example is a simple line after a plot: legend('Curve1','Curve2',1);
While it used to work fine prior to R2016b, we see the following response :
Error using legend>process_inputs (line 582) Invalid argument. Type 'help legend' for more information.
Error in legend>make_legend (line 340) [autoupdate,orient,location,position,children,listen,strings,propargs] = process_inputs(ha,argin); %#ok
Error in legend (line 294) make_legend(ha,args(arg:end),version);
Error in Script_plot (line 274) legend('Curve1','Curve2',1);
回答 (3 件)
Star Strider
2017 年 3 月 27 日
The numeric location designations have been deprecated. Use the 'Location' name-value pair instead:
legend('Curve1','Curve2', 'Location','NE')
6 件のコメント
Shlomit Beker
2018 年 10 月 5 日
This solution doesn't work for me (2017a). Any other solution for this problem?
Walter Roberson
2018 年 10 月 5 日
plot(1:10,rand(1,10),1:10,rand(1,10)); legend('Curve1','Curve2', 'Location','NE')
Looks fine to me in R2017a.
Thomas Riedler
2024 年 10 月 2 日
I have some old code where to numerical location designations are present. Could you please tell me which number corresponds to which location?
@Thomas Riedler — Probably the best way to do that iis to use the 'DisplayName' name-value pair in each plot call —
t = linspace(0, 1);
y1 = sin(2*pi*t);
y2 = cos(2*pi*t);
figure
plot(t, y1, 'DisplayName','Sine')
hold on
plot(t, y2, 'DisplayName','Cosine')
hold off
grid
legend('Location','best')
This should workj for all recent MATLAB releases. (I don’t remember how long 'DisplayName' has been available.) See Specify Legend Labels During Plotting Commands for details.
.
In the versions that are old enough:
% 0 = 'Best'
% 1 = 'NorthEast'
% 2 = 'NorthWest'
% 3 = 'SouthWest'
% 4 = 'SouthEast'
% -1 = 'NorthEastOutside'
These were deprecated in R2013b, and were removed before R2015b
Thomas Riedler
2024 年 10 月 3 日
Thank you, that's what I was searching for!
Kim Hans
2017 年 6 月 3 日
0 投票
I have the same problem with matlab 2017a. So can help me ?
1 件のコメント
Steven Lord
2017 年 6 月 3 日
See Star Strider's answer.
Sebastien AMIOT
2017 年 6 月 6 日
0 投票
2 件のコメント
Star Strider
2017 年 6 月 6 日
You have to go back and manually change all the legend calls in your old code.
Walter Roberson
2017 年 6 月 7 日
Write your own legend.m function that you put higher in the priority and which detects the use of the old style calls and converts the arguments and calls the built-in legend
カテゴリ
ヘルプ センター および File Exchange で Legend についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
