Search code examples
matlabgnuplotoctave

How to mark co-ordinates of points in Octave using "plot" command?


I am using the plot command in Octave to plot y versus x values. Is there a way such that the graph also shows the (x,y) value of every coordinate plotted on the graph itself?

I've tried using the help command but I couldn't find any such option.

Also, if it isn't possible, is there a way to do this using any other plotting function?


Solution

  • Have you tried displaying a text box at each coordinate?

    Assuming x and y are co-ordinates already stored in MATLAB, you could do something like this:

    plot(x, y, 'b.');
    for i = 1 : numel(x) %// x and y are the same lengths
        text(x(i), y(i), ['(' num2str(x(i)) ',' num2str(y(i)) ')']);
    end
    

    The above code will take each point in your graph and place a text box (with no borders) in the format of (x,y) where x and y are the coordinates for all of the points.

    Note: You may have to play around with the position of the text boxes, because the above code will place each text box right on top of each pair of co-ordinates. You can play around by adding/subtracting appropriate constants in the first and second parameters of the text function. (i.e. text(x(i) + 1, y(i) - 1, .......); However, if you want something quick and for illustrative purposes, then the above code will be just fine.