在MATLAB使用histfit,怎么设置双纵坐标,因为数据的基数差异很大,一条曲线在很下面.现有代码:h1=histfit(data1,20);set(h1(1),'Visible','off');set(h1(2),'Color','g');hold on ;h2=histfit(data2

来源:学生作业学帮网 编辑:学帮网 时间:2024/07/04 07:31:25

在MATLAB使用histfit,怎么设置双纵坐标,因为数据的基数差异很大,一条曲线在很下面.
现有代码:
h1=histfit(data1,20);
set(h1(1),'Visible','off');
set(h1(2),'Color','g');
hold on ;
h2=histfit(data2,20);
set(h2(1),'Visible','off');
set(h2(2),'Color','r');

做两组随机分布数


单坐标轴



双坐标



代码如下:
clear all;
close all;
data1 = rand(1,100);
data2 = rand(1,500);

fig = figure;
h1=histfit(data1,20);
set(h1(1),'Visible','off');
set(h1(2),'Color','g');
box off;
ax1 = gca;
hold on ;

ax2 = axes;
h2=histfit(data2,20);
set(h2(1),'Visible','off');
set(h2(2),'Color','r');
set(ax2,'YAxisLocation','right','color','none','box','off','xlim',get(ax1,'xlim'),'XTickLabel',[]);


这种画法比较啰嗦,其实最好的办法还是用normfit直接估计出分布函数,再用plotyy画更为合理