在 Matlab 中的两个地图轴之间切换

Switch between two map axes in Matlab

有没有办法在Matlab的绘图工具箱中切换两个地图轴?

我创建了底图,然后创建了一个小插图以在更缩小的上下文中显示地图位置。

我想返回并添加到第一张地图,但插图现在处于活动状态,因此如果我随后使用 plotm(lat, lon) 它会出现在小插图上。

我知道我可以改变绘图的顺序并最后绘制插图,但此时我还没有决定我希望最终地图看起来如何,所以在这个 "exploration phase" 我想要如果可能的话,能够动态地在两个地图轴之间切换。理想情况下,我想让底图成为一个我可以重复调用和添加的函数。

简化的示例代码:

figure(10);
% create main map
ax1 = axesm('mercator', 'MapLatLim', [33.12 33.48], 'MapLonLim', [-118.9 -118.3], 'Frame', 'on');
states = shaperead('usastatehi', 'UseGeoCoords', true, 'BoundingBox', [-118.9 33.12; -118.3 33.48]);
geoshow(states, 'FaceColor', [0 0 0], 'EdgeColor', 'k')

% create inset
gInset = axes('position', [0.60 0.18 .18 .14], 'Visible', 'off');
ax2 = axesm('mercator', 'MapLatLim', [32.2 34.8], 'MapLonLim', [-121.5 -116.5], ...
    'Frame', 'on', 'FLineWidth',1);
geoshow(states, 'FaceColor', [0 0 0], 'EdgeColor', 'k')

% add something to main map
plotm([33.2 33.45], [-118.5 -118.6])

Cecilia 已经找到了答案,但如果您需要,这里还有更多细节。

您可以使用轴函数来设置当前活动轴并在它们之间切换。要在您的代码中执行此操作:

figure(10);
% create main map
ax1 = axesm('mercator', 'MapLatLim', [33.12 33.48], 'MapLonLim', [-118.9 -118.3], 'Frame', 'on');
states = shaperead('usastatehi', 'UseGeoCoords', true, 'BoundingBox', [-118.9 33.12; -118.3 33.48]);
geoshow(states, 'FaceColor', [0 0 0], 'EdgeColor', 'k')

% create inset
gInset = axes('position', [0.60 0.18 .18 .14], 'Visible', 'off');
ax2 = axesm('mercator', 'MapLatLim', [32.2 34.8], 'MapLonLim', [-121.5 -116.5], ...
    'Frame', 'on', 'FLineWidth',1);
geoshow(states, 'FaceColor', [0 0 0], 'EdgeColor', 'k')

% add something to main map
plotm([33.2 33.45], [-118.5 -118.6])
figure(10);
% create main map
ax1 = axesm('mercator', 'MapLatLim', [33.12 33.48], 'MapLonLim', [-118.9 -118.3], 'Frame', 'on');
states = shaperead('usastatehi', 'UseGeoCoords', true, 'BoundingBox', [-118.9 33.12; -118.3 33.48]);
geoshow(states, 'FaceColor', [0 0 0], 'EdgeColor', 'k')

% create inset
gInset = axes('position', [0.60 0.18 .18 .14], 'Visible', 'off');
ax2 = axesm('mercator', 'MapLatLim', [32.2 34.8], 'MapLonLim', [-121.5 -116.5], ...
    'Frame', 'on', 'FLineWidth',1);
geoshow(states, 'FaceColor', [0 0 0], 'EdgeColor', 'k')

% add something to main map
axes(ax1)
plotm([33.2 33.45], [-118.5 -118.6])

% to go back to ax2 and add to that again
axes(ax2)