MATLAB Answers

Suplabel Causes the Second Y Axis Data to Disappear

2 views (last 30 days)
Marie
Marie on 15 Apr 2016
Commented: Marie on 19 Apr 2016
Hi,
I'm using the function suplabel to put a master title on a graph with 6 subplots. The three subplots on the left are generated using the plotyy function. As long as the superlabel is not used, both sets of data appear on the left side graphs. As soon as I place the superlabel, though, the second dataset disappears in all three graphs (but the ticks and label remain).
I've tried using hold on to keep everything in place, but that doesn't work. I also tried placing the superlabel at the very start of the graph generation, again with no luck. I've included the code below, but I'm not sure how much help it would be.
Appreciate any insights, and thanks in advance.
figure(q1)
subplot(3,2,1)
[ax1,h11,h12]=plotyy(minuteFilter(:,1),minuteFilter(:,5),minuteFilter(:,1),minuteFilter(:,8));
set(ax1(1),'XTick',[736424;736425;736426;736427;736428]);
set(ax1(2),'XTick',[736424;736425;736426;736427;736428]);
datetick(ax1(1),'x',0,'keepticks');
datetick(ax1(2),'x',0,'keepticks');
ylabel(ax1(1),'Sensor Reading');
ylabel(ax1(2),'Temperature, C','rot',-90);
grid on
hold on
title('X Axis Data')
%
subplot(3,2,3)
[ax2,h21,h22]=plotyy(minuteFilter(:,1),minuteFilter(:,6),minuteFilter(:,1),minuteFilter(:,8));
set(ax2(1),'XTick',[736424;736425;736426;736427;736428]);
set(ax2(2),'XTick',[736424;736425;736426;736427;736428]);
datetick(ax2(1),'x',0,'keepticks');
datetick(ax2(2),'x',0,'keepticks');
ylabel(ax2(1),'Sensor Reading');
ylabel(ax2(2),'Temperature, C','rot',-90);
grid on
hold on
title('Y Axis Data')
%
subplot(3,2,5)
[ax3,h31,h32]=plotyy(minuteFilter(:,1),minuteFilter(:,7),minuteFilter(:,1),minuteFilter(:,8));
set(ax3(1),'XTick',[736424;736425;736426;736427;736428]);
set(ax3(2),'XTick',[736424;736425;736426;736427;736428]);
datetick(ax3(1),'x',0,'keepticks');
datetick(ax3(2),'x',0,'keepticks');
ylabel(ax3(1),'Sensor Reading');
ylabel(ax3(2),'Temperature, C','rot',-90);
grid on
hold on
title('Z Axis Data')
%
subplot(3,2,2),plot(minuteFilter(:,5),minuteFilter(:,9),'b.',minuteFilter(:,5),minuteFilter(:,10),'r.',minuteFilter(:,5),minuteFilter(:,11),'k.');
legend('XY','XZ','ZY');
grid on
hold on
title('Calculated Angle as a Function of X Axis Data');
xlabel('X-Axis Sensor Output');
ylabel('Calculated Angle, degrees');
subplot(3,2,4),plot(minuteFilter(:,6),minuteFilter(:,9),'b.',minuteFilter(:,6),minuteFilter(:,10),'r.',minuteFilter(:,6),minuteFilter(:,11),'k.');
legend('XY','XZ','ZY');
grid on
hold on
title('Calculated Angle as a Function of Y Axis Data');
xlabel('Y-Axis Sensor Output');
ylabel('Calculated Angle, degrees');
subplot(3,2,6),plot(minuteFilter(:,7),minuteFilter(:,9),'b.',minuteFilter(:,7),minuteFilter(:,10),'r.',minuteFilter(:,7),minuteFilter(:,11),'k.');
legend('XY','XZ','ZY');
grid on
hold on
title('Calculated Angle as a Function of Z Axis Data');
xlabel('Z-Axis Sensor Output');
ylabel('Calculated Angle, degrees');
hold on
mastertitle={sprintf('%s Using %s & Connector %d,',USR,SN,Conn);'Sensor Outputs (Filtered in 60s Intervals) as a Function of Time'};
suplabel(char(mastertitle),'t');

  0 Comments

Sign in to comment.

Accepted Answer

Anish Mitra
Anish Mitra on 19 Apr 2016
I am assuming you are using the following File Exchange submission for 'suplabel' :
The behavior is because of line 86 in the code, suplabel.m :
for k=1:length(currax), axes(currax(k));end % restore all other axes
I believe this might not have been intended to work with 'plotyy'. Essentially, if the first axis (left) is set as the current axes in the figure it overlaps the second axis (right). This can be seen in the following code snippet :
>> figure;
>> ax = plotyy(1:10,rand(1,10),1:10,rand(1,10));
>> axes(ax(1))
The following command then brings the second axes to the front, and both sets of data can be observed.
>> axes(ax(2))
Commenting out line 86 in suplabel.m does solve this issue here, but I am not sure how it will impact other use cases. I believe the author of the File Exchange submission would be the best person to answer this.
Also, you can contact MathWorks Technical Support (<mailto:support@mathworks.com support@mathworks.com>) for the above code snippet and why there is an overlapping of the first axes, and not the second.

  1 Comment

Marie
Marie on 19 Apr 2016
Great, thank you. I shall try it and see how it works. Worst case, I can create a use-case-specific version of suplabel. But, now I know for future projects.

Sign in to comment.

More Answers (0)