MATLAB: Legends as pointers in matlab plot

lengends

I have plotted a India map and over that, I have used geoshow to show few stations. I have assigned all the plane stations by blue dots and other stations by black triangular dots. How can I put these two things in the legend in matlab plot?

Best Answer

The easiest way is to create a fake graphics object with coordinates NaN, NaN but with the appropriate shape and color and line attributes; do this repeatedly for each entry and record the handles. Then legend() against those handles with appropriate text in a cell array.
For example,
L(1) = plot(nan, nan, 'b.', 'MarkerSize', 5);
T{1} = 'Urmar Tanda';
L(2) = plot(nan, nan, 'b*', 'MarkerSize', 5);
T{2} = 'Pattamundai';
L(3) = plot(nan, nan, 'kv', 'MarkerSize', 8);
T{3} = 'Lakheri';
L(4) = plot(nan, nan, 'k^', 'MarkerSize', 8);
T{4} = 'Sirsa';
legend(L, T)