Question

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.

Was it helpful?

Solution

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. It could be done with xlim in a similar way.

enter image description here

OTHER TIPS

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,

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top