How to have two legends on the same plot?
1 个评论
Hi @ Miguel Martinez,
To address your query regarding, “ However, when using semilogy it didn't work”
First, generate some sample data for plotting. For this example, we will create two sets of data.
x = 1:10;
y1 = 10 ./ x;
y2 = log(x);
Plot the data using the semilogy function.
semilogy(x, y1, 'b', x, y2, 'r');
Add legends for both datasets using the legend function. To display two legends, you can use the legend function twice.
legend('Data 1', 'Data 2'); legend('Location', 'northwest'); % Adjust the location of the first legend
If you want, you can customize the legends further by specifying the location, font size, font weight, etc. For example:
legend('Data 1', 'Data 2', 'Location', 'northwest', 'FontSize', 10, 'FontWeight', 'bold');
Please see attached plot.

回答(2 个)
2 个评论
类别
在 帮助中心 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

