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!

