How to create one common legend for 4 subplots in MATLAB?

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

enter image description here

+3


source to share


2 answers


Fast 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'));

      



enter image description here

+2


source


Well, I just found out about it.

You can simply add a legend to the last subtitle and then drag and drop the legend wherever you want. (The last sub-heading will adjust the size itself, so you don't need to worry about that): |



But actually I want to find a MATLAB function (for example, use "suptitle" to add a generic title for a subtitle) or some MATLAB code for that. So if you find this feature now, please let me know. Thank!

0


source







All Articles