How to create one common legend for 4 subplots in

2019-07-07 08:19发布

问题:

How can I create one common legend for 4 subplots in MATLAB, like this:

回答1:

Quick and dirty:

hSub = subplot(3,1,1); plot(1,1,1,1,1,1,1,1);
hLegend = legend('hello','i','am','legend');

subplot(3,2,3), plot(10:-1:1); subplot(3,2,4), plot(1:100);
subplot(3,2,5), stem(1:10); subplot(3,2,6), plot(randn(1,100))

set(hLegend, 'position', get(hSub, 'position'));