如何在MATLAB中为4个子图创建一个公共图例?

3
我该如何在MATLAB中为4个子图创建一个共同的图例,就像这样:enter image description here

我碰巧知道一个解决方案。您只需将图例添加到最后一个子图中,然后将图例拖动到所需位置即可。(最后一个子图会自动调整其大小,因此您不必担心):|但实际上,我想找到一个MATLAB函数(例如使用“suptitle”为子图添加公共标题)或一些MATLAB代码来完成此操作。因此,如果您现在找到了该功能,请告诉我。谢谢! - Lucida
1个回答

2

简单直接:

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


我之前尝试过这个方法,但它的缺点是图例会使主要子图变小。 - ahammadz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接