How to plot my grafik in a gui axes ?
1 次查看(过去 30 天)
显示 更早的评论
Hi, I wrote a script that plots a map from some given ways and nodes structs data (my plot works fine), then I tried to plot this thing in a GUI Axes, first by copying my code and pasting it under the pushbutton function in the Matlab GUI function and then I tried some other stuff but nothing has worked.
this is my code that plots fine but how to plot it in a GUI Axes ???:
%plot ways
for i=1:1:length(ways)
value = getfield(ways(i), 'latLon');% acces field
plot(value(:,2),value(:,1));
set(gca,'color',[0.8 0.8 0.8])% color the backround
hold on
end
%plot nodes
for i=1:1:length(nodes)
value1 = getfield(nodes(i), 'latLon');
plot(value1(:,2),value1(:,1),'o')
end
%plot within this x and y boundries
xlim([bounds.minLon bounds.maxLon]);
ylim([bounds.minLat bounds.maxLat]);
%begin the filling and drwing process
for i=1:1:length(ways)
mytags = getfield(ways(i), 'tags'); %get all of my tags
mykeys = keys(mytags); % get all of my tags keys
myvalues = values(mytags); % get all of my tags values
%fill buildings
bu= find(contains(mykeys,'building')); % find the word building in mykeys
if ~isempty(bu) %if the word exist( buil is not empty)
vn=getfield(ways(i), 'latLon');
fill(vn(:,2),vn(:,1),[0.8 0.6 0.2]); % fill my building
end
end
0 个评论
回答(1 个)
Jan
2018-5-13
Do not use gca to obtain the handle of an axes, but specify the handles of an existing axes object:
plot(value(:,2),value(:,1));
set(gca,'color',[0.8 0.8 0.8])%
==>
ax = handles.axes1;
plot(ax, value(:,2),value(:,1));
set(ax,'color',[0.8 0.8 0.8])
Specify the axes in the other commands also:
xlim(ax, [bounds.minLon bounds.maxLon]);
ylim(ax, [bounds.minLat bounds.maxLat]);
fill(ax, vn(:,2),vn(:,1),[0.8 0.6 0.2]);
By the way, getfield is not convenient. Compare:
vn = getfield(ways(i), 'latLon');
vn = ways(i).latLon;
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!