octave - Octave 图中的附加图例或文本框窗口

标签 octave

我想在我的绘图中添加带有注释的文本或图例框。

目前我的图例绘制在东北外,我想将新的图例(或文本框)添加到东南外的位置。

谢谢!

最佳答案

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

据我所知,一个坐标区对象只能有一个图例对象。您可以使用第二个轴对象创建第二个图例。每个图例仅列出与每个轴关联的数据元素。改编自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

关于octave - Octave 图中的附加图例或文本框窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38747842/

相关文章:

matlab - 为什么这些线性不等式约束在 Matlab 中有效但在 Octave 中无效?

r - 如何使用 R 4.1 中的 Octave?

c - 为什么这段代码没有调用 Matlab 函数

machine-learning - 梯度下降似乎失败了

matlab - 在 MATLAB/Octave 中矢量化三角形扫描线

matlab - 为什么 inv(matrix)*matrix 不是 Octave 中的精确单位矩阵?

c++ - 运行简单的 .oct 文件时 Octave 崩溃,我的代码有什么问题?

matlab - 等效于 Lua 解释器的 Matlab "whos"命令?

matlab - 在 Octave/Matlab 的 arrayfun 中使用 if 子句

matlab - 为什么我收到警告 "epstool binary is not available",带有 saveas(gcf ,'filename.pdf' )