2014-04-20 788 views
0

考慮到this question,我試圖用兩個獨立的plot使用座標軸而不是plotyy來解決問題,該座標不能與'boxplot'和'plot ':繪製兩個不同的圖(y軸),在matlab中共享相同的x

%%% 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); 

但仍然沒有得到我的最後陰謀正確的方式。有誰知道爲什麼?

+0

請張貼可執行代碼。 (什麼是box_panda_8?) – thewaywewalk

+0

@thewaywewalk,請看現在更新的問題;) – Amir

回答

1

在最後一行之前沒有hold on

+0

我是多麼愚蠢! tnx @丹尼爾,提到這一點!我仍然不知道爲什麼matlab的內置功能,即'plotyy'不起作用,因爲我正在使用'plotyy(x,MPG,x,y2,'boxplot','plot')' – Amir

相關問題