How to use linkaxes on two heatmaps in App Designer?
3 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Mario Malic
on 28 Aug 2024
Edited: Mario Malic
on 28 Aug 2024
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
0 Comments
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!