A customized legend using LaTeX

7 ビュー (過去 30 日間)
Igor Markiewicz
Igor Markiewicz 2017 年 12 月 27 日
コメント済み: John K. George 2021 年 9 月 14 日
Hello! I wanted to make a customized legend for two functions on the same graph and I need both flat text and LaTeX support. At the moment I built something like this:
figure;
N = 1:1:length(train_value);
plot(N, train_value, N, test_value, 'LineWidth', 1.5);
xlabel('numer iteracji', 'fontweight', 'bold');
ylabel('\boldmath$\overline{\kappa}_C$', 'Interpreter', 'latex', 'fontweight', 'bold', 'fontsize', 17);
l = legend('XXX', 'YYY');
set(l, 'Interpreter', 'latex', 'string', 'warto\''s\''c \boldmath${\overline{\kappa}_C}$ dla zbior\''ow treningowych', 'Interpreter', 'latex', 'string', 'warto\''s\''c \boldmath${\overline{\kappa}_C}$ dla zbior\''ow testowych');
It works almost well. The only problem is that the last settings instead of being added overwrite the first settings. As a result, I have a legend for only one graph.

採用された回答

Star Strider
Star Strider 2017 年 12 月 27 日
編集済み: Star Strider 2017 年 12 月 27 日
I would put the LaTeX strings in the legend entries themselves, then define the interpreter in the set call.
Example
x = 1:10; % Create Data
y1 = randn(1, 10); % Create Data
y2 = rand(1, 10); % Create Data
figure(1)
plot(x, y1, 'pg', x, y2, 'pr')
l = legend('$e^{x}$', '$U(x)$');
set(l, 'interpreter', 'latex')
  1 件のコメント
John K. George
John K. George 2021 年 9 月 14 日
This code (below) works for me;...however, I need to display one legend with multiple plots of "string(app.selectedData1)". Currently, only the most recent selectedData1 is displayed in legend. How do I update the code here (below), to display all values of string(app.selectedData1)??
plot(data(:,1), data(:,2),'DisplayName',string(app.selectedData1))
t = legend(string(app.selectedData1),'Interpreter','latex')

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by