필터 지우기
필터 지우기

How to use linkaxes on two heatmaps in App Designer?

조회 수: 4 (최근 30일)
hanspeter
hanspeter 2024년 8월 28일
편집: Mario Malic 2024년 8월 28일
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