【发布时间】:2021-03-07 05:50:46
【问题描述】:
我正在从文件中读取数据并将文件名用作图例,但 Octave 无法正确呈现原始文件名(大写)。
这是我的 Octave 脚本(带有虚拟绘图数据)
files = dir('*.ASC');
fileName = "";
figure
title ("lower case");
xlabel ("xdata");
ylabel ("ydata");
for i = 1:length(files(:,1))
fileName = files(i,1).name;
x = i*2
plot(x, x + 5*x^2, 'DisplayName', lower(fileName));
hold on;
endfor
h = legend ("location", "northeastoutside");
legend (h, "location", "northeastoutside");
set (h, "interpreter", "tex");
hold off;
grid on;
figure
title ("UPPER CASE");
xlabel ("xdata");
ylabel ("ydata");
for i = 1:length(files(:,1))
fileName = files(i,1).name;
x = i*2
plot(x, x + 5*x^2, 'DisplayName', toupper(fileName));
hold on;
endfor
h = legend ("location", "northeastoutside");
legend (h, "location", "northeastoutside");
set (h, "interpreter", "tex");
hold off;
grid on;
【问题讨论】:
-
您可以使用
get和set查询/修改任何图形对象(包括图例框)的属性。 -
顺便说一句,我无法重现该问题。默认值在我的设置中运行良好。也许您有一个小型显示器,它限制了图形的可能大小。您可以尝试强制使用足够大的图形大小,以确保图例框中的名称有足够的空间等。
-
我还没有找到如何获取或设置图例的框宽度。我该怎么做?
-
盒子的宽度由它的'position'属性决定。例如。试试这个:
LPos = get(h, 'position'); LPos += [-0.01, 0, 0.01, 0]; set(h, 'position', LPos);将框向左移动 1%(图形宽度),同时将其宽度扩展相同的量。 -
谢谢,但这不会调整图例框的大小。我正在使用 Octave 5.2.0。
标签: plot octave legend word-wrap legend-properties