How to have a common label for all x and y axes in case of subplots?

假装没事ソ 提交于 2019-12-31 04:11:22

问题


I have used the following loop to get subplots:

for j=1:19;
    Aj=B(j,:);
    subplot(5,4,j);
    plot(Aj,h)
end

For all these subplots, I need to have only one x-label and one y-label. How to do this? Also how to insert legend to all the subplots?


回答1:


You can use suplabel from the FileExchange to have combined x and y label for all subplots.

Example:

subplot(1,2,1);
plot(randperm(40)); hold on; plot(randperm(40));  %Plotting some random data
legend('show')   %To show the legend

subplot(1,2,2);
plot(randperm(40)); hold on; plot(randperm(40));  %Plotting some random data
legend('show')   %To show the legend

%Using suplabel from the FileExchange to give a single x and y label for all subplots
suplabel('Combined X label','x');
suplabel('Combined Y label','y');

Output:


Sometimes you have to maximize the figure window to see the xlabel when using suplabel.



来源:https://stackoverflow.com/questions/42695667/how-to-have-a-common-label-for-all-x-and-y-axes-in-case-of-subplots

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!