How to use linkaxes on two heatmaps in App Designer?

2 次查看(过去 30 天)
Hello everyone,
in App Designer I want to create an app that opens two measurement files and displays the data of each file in a heatmap. This works so far. Now I want to link both heatmaps so that when I zoom into one the other one zooms in as well. That's my attempt:
t = tiledlayout(app.Panel, 1, 2);
ax1 = nexttile(t);
heatmap1Hndl = heatmap(t, tbl1, x, y, "ColorVariable",z);
ax2 = nexttile(t);
heatmap2Hndl = heatmap(t, tbl2, x, y, "ColorVariable",z);
linkaxes([ax1 ax2]);
Doing that throws the error "Error using linkaxes. There must be at least one valid axes."
What am I doing wrong?

回答(1 个)

Mario Malic
Mario Malic 2024-8-28
编辑:Mario Malic 2024-8-28
Hello,
The graphs can't be linked, since they are not axes object.
Here's a dirty approach, there are lots of assumptions, including that all heatmap charts have same X and Y labels. I am not sure if this fits your case, but you get the idea. You have to click on it first so it becomes the CurrentAxes, then use the scroll button to zoom in the charts,
T = readtable('outages.csv');
hFig = uifigure("WindowScrollWheelFcn", @ZoomHeatmap);
hTL = tiledlayout(2, 1, "Parent", hFig)
h1 = heatmap(hTL, T, 'Region','Cause');
nexttile(hTL)
h2 = heatmap(hTL, T, 'Region','Cause');
function ZoomHeatmap(src, event)
% Get layout, assuming only one exists
hLayout = findall(src, "type", "tiledlayout");
hHeatmaps = hLayout.Children;
% Obtain CurrentAxes from UIFigure and use its XLim and YLim property to assign
% to other objects
hCurrHeatmap = src.CurrentAxes;
hIdxFound = eq(hCurrHeatmap, hHeatmaps);
% Update properties
hHeatmaps(~hIdxFound).XLimits = hCurrHeatmap.XLimits;
hHeatmaps(~hIdxFound).YLimits = hCurrHeatmap.YLimits;
end

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by