Question

I know that one can insert a colorbar by clicking the colorbar icon in the clustergram GUI. Is there a way to do it programmatically? I tried

cgo = clustergram(data)
colorbar;

This makes a colorbar in a new figure window. How can a colorbar be created with proper positioning in a clustergram figure as if the button was clicked?

Was it helpful?

Solution

There is a function buried away (HeatMap.plot>showColorbar) that neatly positions the colorbar to the left of both the heat map and the dendogram (the lines). Just running colorbar(...) will mess up the relative positioning of the dendogram and the heatmap. So you need to somehow run the callback or carefully duplicate all of the position computations. It's easier to just run the callback. Here's how.

To create the colorbar programmatically for a clustergram, and keep the color bar button in sync, you need to use the button's assigned callback and set the button's state.

Create the clustergram:

load filteredyeastdata
cgo = clustergram(yeastvalues(1:30,:),'Standardize','Row');

Get the handle for color bar button:

cbButton = findall(gcf,'tag','HMInsertColorbar');

Get callback (ClickedCallback) for the button:

ccb = get(cbButton,'ClickedCallback')
ccb = 
    @insertColorbarCB
    [1x1 clustergram]

That gives us a handle to the function assigned by the callback (@insertColorbarCB), and the function's third input argument (the clustergram object). The button's handle and an empty event object are implicitly the first two arguments.

Change the button state to 'on' (clicked down):

set(cbButton,'State','on')

Run the callback to create the colorbar:

ccb{1}(cbButton,[],ccb{2})

Note that the button State must be changed to 'on' first, otherwise the callback won't do anything.

OTHER TIPS

I just managed to solve this problem. What I did:

I added this function to the clustergram code (I put it at line 1486)

    %%%%%%%%%%%%%%

    function insertColorbarCBALWAYS(obj)

         hFig= gcbf;

         obj.Colorbar = true;

    end
    %%%%%%%%%%%%%%%

and then at line 415 of the clustergram.m file I added this line of code

insertColorbarCBALWAYS(obj);

to call the above function. Save and go: now the colorbar will always be there, once the clustergram is drawn. Previous method was not working for me so I made this workaround. One may even save the new clustergram code as clustergramCM such that you can draw cgram in both ways.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top