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!

 Akzeptierte Antwort

Shubham Gupta
Shubham Gupta am 7 Jan. 2019

0 Stimmen

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.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by