在图例和标签中使用 LaTeX?

Using LaTeX in legends and labels of plots?

我正在尝试添加一个图例,其中包含绘制在绘图上的函数,例如:

description = legend({"y(x) = \sqrt{\frac{100(1-0.10x^2)^2+0.02x^2}{(1-x^2)^2+0.1x^2}}"});

legend(description ,"location", "northoutside");

然而,我得到的结果是:

包含 LaTeX 数学模式符号的正确语法是什么?


Octave-4.2.1 Windows 10

我可以确认这在 matlab 中有效:

p = plot(1:10);
description = '$y(x) = \sqrt{\frac{100(1-0.10x^2)^2+0.02x^2}{(1-x^2)^2+0.1x^2}}$';
l = legend(description);
set(l, 'interpreter', 'latex');

但不是八度。

所以大概安迪在链接 post 中提到的问题仍然存在。

我知道这并不理想,但作为一种解决方法,我会简单地导入一个预渲染的乳胶图像 axes,然后手动将其放在主图 [=12] 的顶部=].我发现生成乳胶文本/方程式片段的最快方法是使用 anki。

例如,我用anki生成了这个:

然后在八度音程中我可能会这样做:

PlotAxes = axes();
plot(1:10, 'g');
set (PlotAxes, 'position', [0.1, 0.1, 0.8, 0.7]);

LegendAxes = axes();
[LegendText, Colourmap] = imread('https://i.stack.imgur.com/dOOnQ.png');
LegendText = ind2rgb (LegendText, Colourmap);
imagesc(LegendText);
axis equal tight;
Lims = axis;
hold on;
LegendLine = plot ([-150, -50], [50, 50], 'linewidth', 3, 'g');
hold off;
axis(Lims + [-200, 0, 0, 0]);
set (LegendAxes, ...
   'position', [0.2, 0.85, 0.6, 0.1], ...
   'xtick', [], 'ytick', [], 'box', 'on');

结果:

这种手动放置一开始可能看起来是一件非常麻烦的事情,但一旦你习惯了,我保证你会真正喜欢它。我论文中的所有图形都是 'manually' 定位的(尽管通常以自动方式),因为这让我可以完全控制。

根据您使用的 TeX 数学符号的种类,使用带有 '' 的引号而不是 "".

可能就足够了

例如,

  1. 权力适用于两者中的任何一个。
  2. '\rho' 得到正确的图例,而 "\rho" 没有。对于我测试的其他希腊符号也是如此。
  3. \frac\sqrt 与两者中的 none 一起使用。

我没有找权威资料更详细,你是案例3,单引号不行。 但对其他人来说可能就足够了(对我来说也是如此)。