1
votes

I have 25 pairs of (x,y) co-ordinates. Each of these pairs corresponds to a country. I want to plot the 25 points on a scatter graph, and have the country name for each point directly next to the point on the scatter graph. I can't figure out how to do this in MATLAB or Octave (I have both MATLAB and Octave and don't mind which I use, which is why I'm asking about both).

Let's say I put the (x,y) co-ordinates and corresponding country labels in a matrix of 25 rows and 3 columns, with the labels in the first column. Does anyone know the command I can use for the desired graph?

1

1 Answers

2
votes

Strings don't play well with matrices, so I'm adjusting your storage format slightly. Here's the test data: a 25x2 matrix of coordinates, and a 25x1 cell array of strings.

p = rand(25,2);
names = repmat({'name'}, 25, 1)

You'll have to play with the offsets slightly, but here's the idea:

scatter(p(:,1), p(:,2))
%# Compute some offsets for the lower-left of the text box, based
%# on overall size of the plot
offset_x = diff(xlim) * .01;
offset_y = diff(ylim) * .01;
text(p(:,1)+offset_x, p(:,2)+offset_y, names)