How to use linkaxes on two heatmaps in App Designer?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Mario Malic
le 28 Août 2024
Modifié(e) : Mario Malic
le 28 Août 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 commentaires
Voir également
Catégories
En savoir plus sur Data Distribution Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!