如何在MATLAB图形中将标记放在最小点?

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 实现。

enter image description here


5
假设您知道该点的坐标,您可以执行以下操作:
hold on; % add things to the current figure
plot(x_coord, y_coord, '+r')

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

在 hold on 后面的分号引发了一个意外的符号错误。 - mrk

3

假设您有像yx这样的数据,此代码将绘制最小点。

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

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接