0
votes

I am struggling to draw my two plots, one is a simple x=y and the other is a boxplot using plotyy. Here are the two :

h1=boxplot(box_panda_8(:, [8 16 24 32 128]) ,'symbol','','notch','on','whisker',0.3)

and

h2=plot([0 5],[0 5], 'k--')

given that i am defining the x axis as

x= 0:5

why the plotyy goes wrong (returns not enough input)

plotyy(x,h1,x,h2)

Updated question Tackling the issue with two separate plots using axes:

%%% two y axes
y2 = 1:6;
x2 = 1:6;

% Plot the first data set
hl1 = boxplot(box_panda_8(:, [8 16 24 32 48 128]) ,'symbol','','notch','on','whisker',0.3)
% Get the axes and configure it
ax1 = gca;
set(ax1,'XColor','r','YColor','r')

%Create the new axes
ax2 = axes('Position',get(ax1,'Position'),...
       'XAxisLocation','top',...
       'YAxisLocation','right',...
       'Color','none',...
       'XColor','k','YColor','k');
% Plot the second data set with the new axes
hl2 =plot(x2,y2,'Color','k','parent',ax2);

but still I dont get my final plot in a right way.

1

1 Answers

2
votes

plotyy() is not for merging plots together. Take a look at the documentation for plotyy().

[AX,H1,H2] = plotyy(X1,Y1,X2,Y2,'function1','function2')

Uses function1(X1,Y1) to plot the data for the left axis and function2(X2,Y2) to plot the data for the right axis. So you should be able to do what you're looking for by doing something along these lines:

[AX,H1,H2] = plotyy(boxplot_x,lineplot_x,lineplot_y,@boxplot,@plot);

You can use set() with AX(1) and AX(2) to change axes properties (like titles, labels, tickmarks etc.) for the left and right axis, respectively. You can use set() with H1 and H2 to set line properties for your boxplot and line plot, respectively.

Unfortunately I do not have the stats toolbox so I'm unable to test whether or not this syntax will work for boxplot().

It is also worth noting that plotyy() can be quite annoying to work with, and is limited to two plots. By stacking axes in the same figure with the backgrounds off, you remove this limitation and gain user friendly control over all aspects of each plot. See this question for a basic example.