- Plot the heatmap on an external figure
- Use imagesc() instead to plot the equivalent of a heatmap on your GUI axes.
Heatmap seems to delete axes component
13 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
2 个评论
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 Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!