以八度为单位将标题文本添加到图例块

时间:2016-02-03 12:23:46

标签: plot octave legend-properties

我试图在Octave(like this)的情节中为传奇块添加标题。我已经仔细研究了情节中可用的属性并找到了标题'属性,但是当我设置它时,情节没有变化。

以下是我尝试的一个例子:

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')

返回Data Series,因此我清楚地设置了该属性,但标题未显示在图例上。

是否需要在某处设置其他内容 - 是否在屏幕外绘制标题块,或者是否存在布尔值或导致其被隐藏的内容我已经比较{{上的各种属性1}}与情节的其他组成部分一样,它们看起来都是一样的。

我有什么遗失,或者这是不可能的吗?

1 个答案:

答案 0 :(得分:3)

您的代码在当前开发版本下运行正常, 默认情况下使用graphics_toolkit("qt")current dev version, graphics_tooolkit("qt")

使用相同的开发版本,但graphics_toolkit("gnuplot"), 缺少传奇标题: current dev version, graphics_tooolkit("gnuplot")

不只是"屏幕外"因为减少gca高度 不显示标题。

仍然可以手动设置标题"",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"))

产生 title set "by hand"