Axis stacking above eachother when creating a video and using two seperate x- and y-axes

2 views (last 30 days)
Alexander von Mach
Alexander von Mach on 14 Apr 2021
Answered: Tarunbir Gambhir on 30 Apr 2021
Hello,
I'm currently trying to create a Video with two seperate x- and y-axis but I'm running into a problem where the left x-axis labels and ticks are stacking above eachother and I can't figure out the correct function the prevent this behaviour of happening.
Here is the testing code:
close all
clear all
filename=strcat('minmax.avi');
v = VideoWriter(filename);
open(v);
x1 = linspace(0,1000,100)
y1 = linspace(0,1000,100)
x2 = linspace(1000,2000,50)
y2 = linspace(2000,1000,50)
figure(1)
for i = 1:10
set(gcf, 'Position', [100, 100, 600, 400])
a = plot(x1(1:i),y1(1:i))
%box off
xlim([0,1000])
ylim([0,1000])
if i == 1
xlabel('x [um]')
ylabel('z [um]')
end
hAx(1)=gca;
hAx(2)=axes('Position',hAx(1).Position,'XAxisLocation','top','YAxisLocation','right','color','none');
hold(hAx(2),'on')
b = plot(hAx(2),x2(1:i),y2(1:i),"Color","red")
xlim([1000,2500])
ylim([1000,2500])
hAx(2).XTick = []
ylabel(hAx(2),"Temperature")
title("Linescan")
x = linspace(0, 2*pi, 100);
hl = plot(x, sin(x));
[~, objH] = legend([a; b; hl], {'z - Warpage', 'Temperature','dummy'})
set(findobj(objH, 'Tag', 'dummy'), 'Vis', 'off'); % Make "junk" lines invisible
pos = get(objH(3), 'Pos'); % Get text box position
set(objH(3), 'Pos', [0.1 pos(2:3)], 'String', append('Temperature: ',num2str(round(y2(i),0)),'°C'));
frame = getframe(gcf);
writeVideo(v,frame);
hold(hAx(1),'off')
hold(hAx(2),'off')
hold off;
end
close(v)

Answers (1)

Tarunbir Gambhir
Tarunbir Gambhir on 30 Apr 2021
Try setting the axis limits and ticks outside, before the for loop. Currently, the ticks and limits are being added on every iteration and hence they are getting overlapped.

Community Treasure Hunt

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

Start Hunting!