[英]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')
這將在該點加上紅色加號。
這應繪制最小點,假設您有y
和x
等數據,
plot(x(y==min(y)),min(y),'o')
根據您的需要添加文本可能會比較棘手,但至少這些是坐標。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.