[英]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.