3

我有一条曲线,其中的最小值对肉眼来说并不明显。出于这个原因,我希望使用标记突出显示最小点。

理想情况下,我会用标记突出显示该点,并将其坐标显示在图上的文本中。

4

3 回答 3

8

你可以这样做:

%// Example plot
x = 1:10;
y = randn(1,10);
plot(x,y)

%// Marker at minimum
[ymin imin] = min(y);
xmin = x(imin);
hold on
style = 'ro'; %// red circle. Change as needed
markersize = 10; %// change as needed
plot(x(imin), ymin, style, 'markersize', markersize)

%// Text with coordinates of minimum
offset = -.05; %// vertical offset as a fraction of y-axis span. Change as needed.
text(x(imin),ymin+diff(ylim)*offset,['(' num2str(x(imin)) ',' num2str(ymin) ')'])

%// Enlarge y axis so that text is properly seen, if offset is negative
ylim(ylim+[diff(ylim)*offset*(offset<0) 0])

如果文本靠近左侧或右侧,您可能还想放大x轴。可以用xlim类似的方式完成。

在此处输入图像描述

于 2013-11-12T12:30:32.123 回答
5

假设您知道该点的坐标,您可以执行以下操作:

hold on; % add things to the current figure
plot(x_coord, y_coord, '+r')

这将在该点放置一个红色加号。

于 2013-11-12T11:36:51.943 回答
2

y假设您有类似and的数据,这应该绘制最小点x

plot(x(y==min(y)),min(y),'o')

根据您的需要,添加文本可能会更棘手,但至少这些是坐标。

于 2013-11-12T11:37:38.477 回答