MATLAB Answers

How to add 'Location' as the name one of the legends in a plot?

2 views (last 30 days)
Sai Charan
Sai Charan on 18 Apr 2021
Commented: Sai Charan on 18 Apr 2021
legend('Canada','USA', 'Location', 'bestoutside')
The above code has two countires in legend - Canada and USA
For example,
legend('Canada','Location', 'Location', 'bestoutside')
This does not work? Why?
Can we not name a legend as 'Location'?
If yes, how to?

Accepted Answer

Jonas on 18 Apr 2021
Edited: Jonas on 18 Apr 2021
no problem using a cell as input for the legend function:
hold on;plot(1:4);
legend({'left','location'},'Location', 'bestoutside')
edit: because you asked why it doe not work your way: there are just some keywords when function inputs are processed, if they appear, there often has to be a specific input as following argument

More Answers (0)




Community Treasure Hunt

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

Start Hunting!