Heatmap seems to delete axes component

13 ビュー (過去 30 日間)
Jason
Jason 2020 年 1 月 14 日
コメント済み: Adam Danz 2020 年 1 月 15 日
Hello, I am creating a heatmap and displaying it on an axes component (GUIDE), B is my matrix data.
ax=axes(handles.axes2)
h1 = heatmap(ax,B);
h1.Colormap = cool;
h1.CellLabelFormat = '%.1f';
This works.
However, if in another function (checkbox callback) I try to get the handle to the axes component, it reports its an invalid handle (I do include handles as my argument to the function)
% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% Hint: get(hObject,'Value') returns toggle state of checkbox1
val= get(hObject,'Value')
if val==1
object_handles=findobj(gcf)
axes(handles.axes2)
%I want to just change the colormap of the heatmap and thought I could then do
hh=gca
hh.Colormap = cool;
end
Could the heatmap be deleting my axes component?
Error using axes
Invalid axes handle

採用された回答

Adam Danz
Adam Danz 2020 年 1 月 14 日
編集済み: Adam Danz 2020 年 1 月 14 日
In reference to this part of your quesiton:
ax=axes(handles.axes2)
h1 = heatmap(ax,B);
h1.Colormap = cool;
h1.CellLabelFormat = '%.1f';
"This works."
That code couldn't possibly work for the following reasons.
First, this line below should throw an error since the axes(cax) syntax does not support an output when the input is an axes handle. The only exception would be if handles.axes2 is actually a figure handle which would make that variable name a really bad one.
ax=axes(handles.axes2)
Error using axes
Too many output arguments.
Second, this line below should also throw an error since an axes cannot be specified as the first input (a figure can, though). h = heatmap(parent,___)
h1 = heatmap(ax,B);
Error using heatmap (line 76)
HeatmapChart cannot be a child of Axes.
You cannot plot a heatmap on a GUI axes. Your options are
  1. Plot the heatmap on an external figure
  2. Use imagesc() instead to plot the equivalent of a heatmap on your GUI axes.
  2 件のコメント
Jason
Jason 2020 年 1 月 15 日
Hi Adam, thanks for your help.
1: Yes I have switched and sued imagesc and added lines and text manually.
However you mention below that its not possible to have the heatmap on the axes2 component but it does....albeit It messes things up afterwards.
"This works."
That code couldn't possibly work for the following reasons.
First, this line below should throw an error since the axes(cax) syntax does not support an output when the input is an axes handle. The only exception would be if handles.axes2 is actually a figure handle which would make that variable name a really bad one.
Adam Danz
Adam Danz 2020 年 1 月 15 日
In the line below, I'm assuming handles.axes2 is a figure handle (not an axes handle). If the input were an axes handle, this line would result in an error.
ax=axes(handles.axes2)
Assuming handles.axes2 is a figure handle, ax would be an axes handle.
Then, this line below would throw an error since the parent of a heatmap chart cannot be an axes.
h1 = heatmap(ax,B);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by