[英]How can I put a marker on the minimum point within a MATLAB figure?
I have a curve in which the minimum point is not obvious to the naked eye. 我有一条曲线,其中肉眼看不到最小点。 For that reason I'm looking to highlight the minimum point using a marker.
出于这个原因,我希望使用标记突出显示最小点。
Ideally I would highlight the point with a marker and also have its coordinates displayed in text on the figure. 理想情况下,我会用标记突出显示该点,并在图中的文本中显示其坐标。
You can do it this way: 你可以这样做:
%// 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])
You might also want to enlarge the x axis if the text is close to the left or to the right. 如果文本靠近左侧或右侧,您可能还需要放大x轴。 It could be done with
xlim
in a similar way. 它可以用类似的方式用
xlim
完成。
Assuming you know the coordinates of that point, you can do something like: 假设您知道该点的坐标,您可以执行以下操作:
hold on; % add things to the current figure
plot(x_coord, y_coord, '+r')
This will put a red plus sign at that point. 这将在该点加上红色加号。
This should plot the minimum point(s), assuming you have data like y
and x
, 这应绘制最小点,假设您有
y
和x
等数据,
plot(x(y==min(y)),min(y),'o')
adding the text could be trickier depending on what you want, but at least these are the coordinates. 根据您的需要添加文本可能会比较棘手,但至少这些是坐标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.