繁体   English   中英

如何在MATLAB图中的最小点上放置标记?

[英]How can I put a marker on the minimum point within a MATLAB figure?

我有一条曲线,其中肉眼看不到最小点。 出于这个原因,我希望使用标记突出显示最小点。

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

你可以这样做:

%// 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完成。

在此输入图像描述

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

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

这将在该点加上红色加号。

这应绘制最小点,假设您有yx等数据,

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

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

暂无
暂无

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

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