8

I have the following code, creating figures which I print to files:

f=figure;
set(gcf,'Visible','off');
imagesc (exp_genes_sorted_cut);
h=colorbar;
set(gcf,'Colormap',mycmap);

set(gca, 'xtick', 1:num_tissues_displayed);
set(gca, 'xticklabel', tissues, 'fontsize', 14);
ylabel('Genes', 'Fontsize', 18);
xlabel('Tissues', 'Fontsize', 18);

I want to add legend to the right of the colorbar, and I tried doing so using the legend function, but it is not shown... using the text function places it outside the printanle area. Can anyone help ? Thanks,,,

2
  • 2
    The colorbar is technically your legend for an image (i.e. intensity/color range pointing to specific pixels). If you want to additionally describe, you can use title()to place it above your image. Commented Oct 15, 2012 at 19:49
  • What do you want the legend to show? It is is possible to create dummy plot elements and then use those for a legend. Commented Oct 15, 2012 at 23:39

1 Answer 1

7

A possible workaround (if I understood you correctly):

 N=4;                                                    %  # of data types, hence legend entries
 Data = randi(N,30,30);                                  % generate fake data
 imagesc(Data)                                           % image it
 cmap = jet(N);                                          % assigen colormap
 colormap(cmap)
 hold on
 L = line(ones(N),ones(N), 'LineWidth',2);               % generate line 
 set(L,{'color'},mat2cell(cmap,ones(1,N),3));            % set the colors according to cmap
 legend('A','B','C','D')                                 % add as many legend entries as data

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.