八度绘图中的附加图例或文本框窗口

时间:2016-08-03 15:28:41

标签: octave

我想在我的情节中添加带有评论的文字或图例框。

目前我的传说是在东北外的情节,我想将新的传奇(或文本框)添加到东南外的位置。

谢谢!

1 个答案:

答案 0 :(得分:4)

缺乏有关您案件的更多信息:

据我所知,一个轴对象只能有一个图例对象。您可以使用第二个轴对象创建第二个图例。每个图例仅列出与每个轴关联的数据元素。改编自Matlab Newsgroup thread

a = [1:0.01:2*pi];  %create sample data
b = sin(a);

linehandle1 = line(a,b);  %creates a line plot with handle object
axeshandle1 = gca;  % gets the handle for the axes object just created 
legendhandle1 = legend('y = sin(x)', 'location', 'northeastoutside'); %makes first legend

axeshandle2 = axes('Position',get(axeshandle1,'Position'),'xlim',get(axeshandle1,'xlim'),'ylim',get(axeshandle1,'ylim'),'Visible','off','Color','none'); %makes invisible axes with same position and scaling
linehandle2 = line(pi/2,1,'Color','r','Marker','o','Parent',axeshandle2); %puts data set on 2nd axes
linehandle3 = line(pi,0,'Color','b','Marker','x','Parent',axeshandle2);
legend_handle2 = legend('peak','zero','location','southeastoutside'); %creates legend to go with 2nd axes

figure created with second-axes method.

如果您只想要第二个框中的文字,不一定是图例信息或数据标签,您可以按照上述说明使用注释。这样做的优点是可以更简单地调用,但可能更难获得您想要的确切位置/结果。有大量的属性选项可以调整,以获得所需的外观。示例中显示了一些。可能有更简单的方法根据图例句柄设置大小/位置。

a = [1:0.01:2*pi];  %create sample data
b = sin(a);
plot(a,b);
legendhandle = legend('y = sin(x)','location','northeastoutside');
annotation('textbox',[0.875 0.1 0.1 0.1],'string','my text','edgecolor','k','linewidth',1,'fitboxtotext','off');

enter image description here