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

时间:2014-08-26 12:55:44

标签: matlab

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

由于

2 个答案:

答案 0 :(得分:2)

我认为您正在寻找一种向图表添加文字的方法。

This example应该是一个很好的起点,它会向您展示如何使用text命令或legend

enter image description here

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

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

答案 1 :(得分:2)

您希望使用以下语法使用text注释:

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

enter image description here