【问题标题】:Switch between two map axes in Matlab在 Matlab 中的两个地图轴之间切换
【发布时间】:2020-03-19 19:08:02
【问题描述】:

有没有办法在Matlab的映射工具箱中的两个地图轴之间切换?

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

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

我知道我可以更改绘图顺序并最后做插图,但此时我还没有决定最终地图的外观,所以在这个“探索阶段”我希望能够如果可能的话,在两个地图轴之间动态切换。理想情况下,我想让底图成为一个可以重复调用并添加到的函数。

简化示例代码:

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])

【问题讨论】:

  • 我目前正在下载工具箱,看看它是否可以工作,但我的直觉是使用axes 来设置当前轴。例如axes(ax1)axes(gInset)
  • 是的!这似乎行得通。我试图使用axsm(ax1)切换但没有运气。我必须在添加到ax1后重新打开axes(ax2),但这很棒。

标签: matlab mapping axes multiple-axes


【解决方案1】:

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多