2014-09-13 66 views
1

我有它如何將不同比例的新圖添加到現有直方圖?

enter image description here Matlab的數字與兩個柱狀圖,

hist()函數創建。現在,我想添加在同一圖兩幅地塊(實際上鈴分佈:

enter image description here

,但他們有不同的規模,我想我可以plotyy使用,但我已經有我的第一個情節規模上。 ?圖我如何添加第二個情節規模

回答

2

一般來說,這是做這件事:

%// example data 
rng(0,'twister') 
data = randn(1000,3); 
x = linspace(-4,4,100); 
y = 16 - x.^2; 

%// generate two axes at same position 
ax1 = axes; 
ax2 = axes('Position', get(ax1, 'Position'),'Color','none'); 

%// move second axis to the right, remove x-ticks and labels 
set(ax2,'YAxisLocation','right') 
set(ax2,'XTick',[]) 

%// plot hist and line plot 
hist(ax1,data); hold on 
plot(ax2,x,y) 

ylabel(ax1,'label of hist') 
ylabel(ax2,'label of plot') 
xlabel(ax1,'Hello World!') 

enter image description here