将标题文本添加到八度图例块

Add title text to legend block in octave

我正在尝试为 Octave (like this) 中的图例块添加标题。我已经深入研究了绘图上可用的属性,并找到了 'title' 属性,但是当我设置它时,绘图上没有任何变化。

这是我正在尝试的示例:

a=linspace(0, 2*pi())
h=plot(sin(a))  
hleg = legend("Data 1")
set(hleg, 'title', 'Data Series')

我也试过这个:

hlegtitle = get(hleg, 'title') 
get(hlegtitle, 'string')

其中returnsData Series,所以我明明设置的是属性,但是图例上没有出现标题。

是否还有其他需要在某处设置的东西 -- 标题栏是否正在绘制 off-screen,或者是否有布尔值或其他东西导致它被隐藏 我已经比较了各种属性hlegtitle 与情节的其他组成部分的那些,它们看起来都一样。

我是否遗漏了什么,或者这是不可能的?

您的代码在当前开发版本下运行良好, 默认使用 graphics_toolkit("qt")

使用相同的开发版本,但 graphics_toolkit("gnuplot"), 图例标题丢失:

不只是"off-screen"因为降低了gca高度 不显示标题。

仍然可以设置标题"by hand",用text:

graphics_toolkit("gnuplot")
a = linspace(0, 2 * pi, 101);
h = plot(a, sin(a));
hleg = legend("Data 1")

set(hleg, "title", "Data Series")
# This is changing the gca "position"
legend("location", "northeastoutside")

# Now tweak the gca height, to provide room above the legend
gca_pos = get(gca, "position");
gca_pos(4) *= 0.9;
# The plot width has to be tweaked by hand,
# because the legend position is not reliable
gca_pos(3) = 0.66;
set(gca, "position", gca_pos)

# set text
leg_pos = get(hleg, "position")
x_pos = 1.2;
y_pos = 1.05;
leg_title = "title";
text(x_pos, y_pos, leg_title, 
     "units", "normalized",
     "fontName", get(gcf, "DefaultAxesFontName"),
     "fontSize", get(gcf, "DefaultAxesFontSize"))

产生