Data cursor does not show lat and long values in a contourm plot (worldmap function)

I want to overlay a data set into North America. I used MATLAB's worldmap() function to get just North America and used plotm() to plot the coastline of North America from coast.mat(this file also comes with MATLAB). I then used contourm() to plot my data over the coast lines. The code below shows what I did.
hold on
h= worldmap('na');
c = load('coast.mat');
plotm(c.lat,c.long);
contourm(lat,long,value);
"lat" and "long" contain latitude and longitude and are of sizes,lets say 'm' and 'n'. "value" has the data to be plotted which is a matrix of size m x n. The data plots fine but the only problem is that when I use the data cursor, instead of seeing values used in plotting: latitude for "y", longitude for "x" and "value" for z I see really large numbers for x and y and always a 0 for z.
The return from
h=worldmap('na')
shows similar large values for XLimit and YLimit. I tried to change this to the coordinate limits but the graph basically disappeared with out any error.I also tried creating a custom data cursor but I could not get to accurately change the values to geo coordinates.
Any help would be appreciated!

回答(1 个)

Try using inputm instead of the data cursor.

4 个评论

I tried to use it but was not successful in it. Could not find any examples either.What I tried to do was: [lat,long]=inputm; and use that lat and long to show in the custom datatip function that I have. This does not work.
This is what my data cursor function looks like. I am using data cursor because I want the user to be able to see where they clicked on the map.
%Function for data cursor
function output_txt = new_datacursor(obj,event_obj)
pos = get(event_obj,'Position');
[lat_loc,lon_loc] = inputm;
output_txt = {['lon: ',lon_loc],...
['lat: ',lat_loc]};
disp(pos);
% If there is a Z-coordinate in the position, display it as well
if length(pos) > 2
output_txt{end+1} = ['value: ',num2str(pos(3),4)];
end
And the error/warning I get (in orange than in red colour) is:
Warning: Error occurred while executing callback:
Error using matlab.graphics.shape.internal.AxesLayoutManager/MarkDirty
Attempt to modify the tree during an update traversal
Error in matlab.graphics.shape.internal.AxesLayoutManager>@(obj,evd)(hObj.MarkDirty('all')) (line 351)
Error in matlab.graphics.shape.internal.AxesLayoutManager/addAxesListeners/localReparentCB (line 333)
Strange! I'm afraid I don't understand that warning at all. Does this work for you?
hold on
h= worldmap('na');
c = load('coast.mat');
plotm(c.lat,c.long);
z = peaks(180);
[long,lat] = meshgrid(-179:0,89.5:-.5:0);
contourm(lat,long,z);
[lat_loc,lon_loc] = inputm(1);
t = textm(lat_loc,lon_loc,...
['(',num2str(lat_loc),'\circ N, ',num2str(lat_loc),'\circ S)'],...
'vert','middle','horiz','center');
Similarly, you may be able to use ginput with minvtran.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 MATLAB 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by