Mathematica中文论坛-非官方

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 6854|回复: 0
打印 上一主题 下一主题

给别人画了一个不错的图

[复制链接]

532

主题

603

帖子

3035

积分

论坛元老

Rank: 8Rank: 8

积分
3035
跳转到指定楼层
楼主
发表于 2017-5-22 16:43:57 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
是统计轨迹,并画一定范围之内数据的高斯分布。
真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, 下载次数: 836)

fig_traj_hist.png
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|Mathematica中文论坛-非官方 ( 辽ICP备16001491号-1

GMT+8, 2024-5-4 01:20 , Processed in 0.118676 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表