Heatmap seems to delete axes component

13 visualizzazioni (ultimi 30 giorni)
Jason
Jason il 14 Gen 2020
Commentato: Adam Danz il 15 Gen 2020
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

Risposta accettata

Adam Danz
Adam Danz il 14 Gen 2020
Modificato: Adam Danz il 14 Gen 2020
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 Commenti
Jason
Jason il 15 Gen 2020
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 il 15 Gen 2020
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);

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Distribution Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by