Cut Off subplots in figure window

조회 수: 6 (최근 30일)
Sebastian Netter
Sebastian Netter 2019년 1월 6일
답변: Shubham Gupta 2019년 1월 7일
Hi guys,
I want to plot some results form previous calculations in two subplots by meshes. Additionally i want to plot a colorbar which represents the magnitude of the values in z direction forboth of the plots. I got all of these subplots to work the way i want them to but apparently the right subplot is cut off.
below you see the code of an example and the printed .png-file i created of the same example
x = rand(10,10);
y = x;
z = x;
azleft = 90;
azright = 270;
elleft = 90;
elrright = -90;
topologie = figure;
links = subplot(1,2,1);
mesh(x,y,z)
view(azleft, elleft);
rechts = subplot(1,2,2);
rechts.YAxisLocation = 'right';
mesh(x,y,z)
view(azright, elrright);
posSubplot2 = get(rechts, 'Position');
posSubplot2(1) = posSubplot2(1) + 0.15;
set(rechts, 'Position', posSubplot2);
posSubplot1 = get(links,'Position');
colorbar('Position', [posSubplot1(1)+posSubplot1(3)+0.075 posSubplot1(2) 0.05 posSubplot1(2)+posSubplot1(3)*2.1])
i also would prefer the y-axis of the ricght graph to be displayed on the right side of the graph.
Thanks for your help in advance!

채택된 답변

Shubham Gupta
Shubham Gupta 2019년 1월 7일
Try this:
x = rand(10,10);
y = x;
z = x;
azleft = 0;
azright = 0;
elleft = 90;
elrright = 90;
topologie = figure;
links = subplot(1,2,1);
mesh(x,y,z)
view(azleft, elleft);
rechts = subplot(1,2,2);
mesh(x,y,z)
view(azright, elrright);
rechts.YAxisLocation = 'right'; % Change axis location after rotating
posSubplot2 = get(rechts, 'Position');
posSubplot2(3) = posSubplot2(3) - 0.05; % Reduce width instead of moving
set(rechts, 'Position', posSubplot2);
posSubplot1 = get(links,'Position');
posSubplot1(3) = posSubplot1(3) - 0.05;
set(links, 'Position', posSubplot1);
colorbar('Position', [posSubplot1(1)+posSubplot1(3)+0.05 posSubplot1(2) 0.05 posSubplot1(4)])
Code is pretty much the same but you need to understand how the elements of the Position vector works, hope this helps.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by