Amir
Amir

Reputation: 1428

Plotting two different plots(y axes), sharing the same x in matlab

Considering this question, I am trying to Tackling the issue with two separate plots using axes instead of plotyy which doesn't work well with 'boxplot' and 'plot':

%%% definition of my x=y line axes
y2 = 1:6;
x2 = 1:6;


% Plot the first data set using boxplot, that results in 6 boxes

load carsmall;
boxplot(MPG,Origin)

% 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. Does anyone know why?

Upvotes: 0

Views: 1156

Answers (1)

Daniel
Daniel

Reputation: 36710

There is a hold on missing before the last line.

Upvotes: 1

Related Questions