繁体   English   中英

如何在Matlab中绘制线段的名称?

[英]How to plot the name of a line segment in Matlab?

我想将名称添加到图中绘制的线段中。 例如,我绘制了包含两个端点(0,0)和(3,3)的线段,其名称为segment1。 如何在位置(0,1)上绘制其名称“ segment1”?

谢谢

我认为您正在寻找一种将文本添加到图形中的方法。

这个例子应该是一个很好的起点,它向您展示了如何使用text命令或legend

在此处输入图片说明

% Define initial conditions
t0 = 0;
tfinal = 15;
y0 = [20 20]';
% Simulate the differential equation
tfinal = tfinal*(1+eps);
[t,y] = ode23('lotka',[t0 tfinal],y0);
% Plot the two curves, storing handles to them
% so their DisplayNames can be set
hlines = plot(t,y);
% Compose and display two multiline text
% annotations as cell arrays
str1(1) = {'Many Predators;'};
str1(2) = {'Prey Population'};
str1(3) = {'Will Decline'};
text(7,220,str1)
str2(1) = {'Few Predators;'};
str2(2) = {'Prey Population'};
str2(3) = {'Will Increase'};
text(5.5,125,str2)
% Set DisplayNames for the lines for use by the legend
set(hlines(1),'Displayname','Prey')
set(hlines(2),'Displayname','Predator')
% Center a legend at the top of the graph
legend('Location','north')
% Add a title with bold style
title('Lotka-Volterra Predator-Prey Population Model',... 
  'FontWeight','bold')

请注意,该链接还描述了更多高级功能。

您想使用使用以下语法的文本注释:

  figure

plot([0 3], [0 3]);
hText = text(1 ,0.7,'Segment 1','FontSize',16) % Using (1,1) as a position was not looking good :)

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM