matlab - Plot a legend for both a barplot and a line -


if have barplot , line on same graph, how write legend both? have

hold on h1 = bar([x;y], 0.5); h2 = plot(a, b); l = cell(2,1); l{1,1}='label x'; l{2,1}='label y'; hl=legend(h1, l); set(hl,'fontsize',10,'location','northeast', 'orientation', 'horizontal'); 

this generates legend barplot how add legend entry line plot?

you've passed bar plot handle legend function that's it's going create. can do, however, pass array of handles (and labels) legend , legend entries elements of handles array shown.

h1 = bar([x;y], 0.5); h2 = plot(a, b); labels = {'label x', 'label y'}; l = legend([h1, h2], labels, ...             'fontsize', 10, ...             'location', 'northeast', ...             'orientation', 'horizontal'); 

Comments

Popular posts from this blog

javascript - Hide toolbar of pdf file opened inside iframe using firefox -

Ansible - ERROR! the field 'hosts' is required but was not set -

Copy range with conditional formatting -