heatmap cannot have Axes or uiaxes as parent

3 ビュー (過去 30 日間)
Alexandru Bitca
Alexandru Bitca 2019 年 10 月 17 日
回答済み: Vedant Shah 2025 年 3 月 10 日
The heatmap function, as of release R2019b, cannot have an uiaxes container as a parent.
Any workaround this limitation?
Mathworks, it would be greatly appreciated if this would become a possibility in future releases!
Thank you,
Alex.

回答 (1 件)

Vedant Shah
Vedant Shah 2025 年 3 月 10 日
As per the documentation, it is not possible to place a heatmap inside a UIAxes.However, a similar workflow can be achieved using the UIPanel. To gain greater control over the position, size, and overall layout of the heatmap, consider the following workaround:
  • Use a UIPanel as the parent container for the heatmap to enhance control over positioning and layout.
  • Embedd the heatmap within the UIPanel thus achieving functionality similar to UIAxes, in terms of precise positioning and layout adjustments.
  • This workaround allows precise positioning for a structured layout, layout control for seamless integration, and flexibility to replicate UIAxes functionality when direct embedding is not feasible.
Below is an example code snippet for the approach mentioned above:
% Create UIFigure
fig = uifigure('Name', 'Heatmap Example', 'Position', [100, 100, 500, 400]);
% Create a Panel to Act Like UIAxes
p = uipanel(fig, 'Position', [50, 50, 400, 300]);
% Define heatmap data
cdata = [45 60 32; 43 54 76; 32 94 68; 23 95 58];
xvalues = {'Small','Medium','Large'};
yvalues = {'Green','Red','Blue','Gray'};
% Create heatmap inside the Panel
h = heatmap(p, xvalues, yvalues, cdata);
Here is a screenshot of expected output from the above code snippet:
For a better understanding of the functions used in above workaround, refer to the documentations using the following commands in MATLAB command line:
web(fullfile(docroot, "/matlab/ref/uifigure.html"))
web(fullfile(docroot, "/matlab/ref/uipanel.html"))
web(fullfile(docroot, "/matlab/ref/heatmap.html"))

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by