Mathematica中文论坛-非官方

标题: 给别人画了一个不错的图 [打印本页]

作者: meatball1982    时间: 2017-5-22 16:43
标题: 给别人画了一个不错的图
是统计轨迹,并画一定范围之内数据的高斯分布。
真TMD优雅,我靠。


  1. clear all
  2. clc
  3. clf

  4. dat=load('../data/combine.dat');
  5. n=length(dat(:,1));
  6. x=(1:n)/10;
  7. dat1=dat(500:end,1);
  8. dat2=dat(500:end,2);

  9. bi = linspace(-13,-6,70);
  10. [hi1,bi1]=hist(dat1,bi);
  11. [hi2,bi2]=hist(dat2,bi);


  12. fx=@(b,x)b(1)/sqrt(2*pi*b(2))*exp(-(x-b(3)).^2/(2*b(2)^2));
  13. x_bin=bi;
  14. x1=linspace(min(x_bin),max(x_bin),200);

  15. y1 = hi1;
  16. b0=[35,2,-8];
  17. b=b0;
  18. for l=1:10
  19.     % Solve nonlinear curve-fitting problems in least-squares sense.
  20.     % just a guess.
  21.     b=lsqcurvefit(fx,b,x_bin,y1);
  22.     % Nonlinear regression,
  23.     b=nlinfit(x_bin,y1,fx,b);
  24.    
  25. end
  26. b1=b;
  27. y_hi1 = fx(b1,x1);


  28. y2 = hi2;
  29. b0=[30,2,-11];
  30. b=b0;
  31. for l=1:10
  32.     % Solve nonlinear curve-fitting problems in least-squares sense.
  33.     % just a guess.
  34.     b=lsqcurvefit(fx,b,x_bin,y2);
  35.     % Nonlinear regression,
  36.     b=nlinfit(x_bin,y2,fx,b);
  37.    
  38. end
  39. b2=b;
  40. y_hi2 = fx(b2,x1);


  41.             
  42. % hold on
  43. % plot(bi1,hi1,'r.')
  44. % plot(x1,y_hi1,'r-')
  45. %
  46. % plot(bi,hi2,'b.')
  47. % plot(x1,y_hi2,'b-')

  48. mm_font=14;

  49. h=figure(1);
  50. set(h, 'Position', [100, 100, 800, 400]);
  51. % subplot(1,2,1)

  52. pos1=[0.1 0.1 0.6 0.8];
  53. subplot('position',pos1)
  54. hold on
  55. x_pat1=[ 50 100 100 50];
  56. y_pat1=[-13.1 -13.1 -5.9 -5.9];
  57. h_pat1=patch(x_pat1,y_pat1,'gray')
  58. alpha(h_pat1,0.1);
  59. plot(x,dat(:,1),'r-')

  60. plot(x,dat(:,2),'b-')

  61. axis tight
  62. box on
  63. axis ([0 100 -13.1 -5.9])
  64. set(gca,'fontsize',mm_font);
  65. set(gca,'xtick',[0:10:100]);


  66. % subplot(1,2,2)
  67. pos2=[0.7 0.1 0.2 0.8];
  68. subplot('position',pos2)
  69. hold on

  70. x_pat2=[ 0 50 50 0];
  71. y_pat2=[-13.1 -13.1 -5.9 -5.9];
  72. h_pat2=patch(x_pat2,y_pat2,'gray')
  73. alpha(h_pat2,0.1);

  74. plot(y_hi1,x1,'r-','linewidth',2)
  75. plot(y_hi2,x1,'b-','linewidth',2)

  76. hi = [hi1;hi2]';
  77. h_bar=barh(bi,hi);
  78. h1=h_bar(1);
  79. h2=h_bar(2);

  80. set(h1,'facecolor','r','edgecolor','none','barwidth',2.5)
  81. set(h2,'facecolor','b','edgecolor','none','barwidth',2.5)
  82. axis([0 50 -13.1 -5.9])
  83. set(gca,'ytick',[]);


  84. text(20,-6.5,['\mu=',mat2str(floor(b1(3)*1000)/1000)],'fontsize',mm_font)
  85. text(20,-7.0,['\sigma=',mat2str(floor(b1(2)*1000)/1000)],'fontsize',mm_font)
  86. text(20,-12,['\mu=',mat2str(floor(b2(3)*1000)/1000)],'fontsize',mm_font)
  87. text(20,-12.5,['\sigma=',mat2str(floor(b2(2)*1000)/1000)],'fontsize',mm_font)


  88. set(gca,'fontsize',mm_font);
  89. box on

  90. h=gcf;
  91. fi_na=['../file_img/fig_traj_hist'];
  92. fun_work_li_035_myfig_out(h,fi_na,3);



  93. % plot(dat(:,1),dat(:,2),'.')
复制代码


fig_traj_hist.png (432.17 KB, 下载次数: 935)

fig_traj_hist.png





欢迎光临 Mathematica中文论坛-非官方 (http://www.ilovemathematica.com/) Powered by Discuz! X3.2