graphics_toolkit("qt")
您的代码在默认
使用的当前开发版本下运行良好。
使用相同的开发版本,但是graphics_toolkit("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"))
产生