Matlab 绘制柱状图并标注对应数字值


  
  
  1. close all;
  2. clear;
  3. clc;
  4. x=zeros( 1, 60);
  5. y1=zeros( 1, 60);
  6. data=load( 'passdatadistance.txt');
  7. for i= 1: 60
  8. x(i)=i;
  9. tem=data(i)/ 100+data(i);
  10. end
  11. y1=data;
  12. figure;
  13. bar( x,y1)
  14. title( ' 单日平均出行距离分布')
  15. xlabel( '出行距离/km')
  16. ylabel( '出行人数/人次')
  17. %legend( 'SVM', 1)
  18. axis([ 0 60 0. 0 80000]);
  19. %set(gcf, 'color', 'white')
  20. %set(gca, 'xticklabel', x);
  21. x2=[ 1 2 3 4];%
  22. t1=[ 28 41 21 5 ];
  23. t2=[ 29 42 22 4 ];
  24. t3=[ 28 42 20 4 ];
  25. t=[t1;t2;t3] ';
  26. figure;
  27. bar(x2,t)
  28. for i = 1:length(x2)
  29. text(x2(i)-0.3,t1(i),num2str(t1(i),'%g%% '),...
  30. 'HorizontalAlignment ','center ',...
  31. 'VerticalAlignment ','bottom ')
  32. text(x2(i),t2(i),num2str(t2(i),'%g%% '),...
  33. 'HorizontalAlignment ','center ',...
  34. 'VerticalAlignment ','bottom ')
  35. text(x2(i)+0.3,t3(i),num2str(t3(i),'%g%% '),...
  36. 'HorizontalAlignment ','center ',...
  37. 'VerticalAlignment ','bottom ')
  38. end
  39. title(' 换乘次数比例分布 ')
  40. xlabel('换乘次数 ')
  41. ylabel('分布比例/%')
  42. legend( '2014', '2015', '2016', 3)
  43. axis([ 0 5 0. 0 50]);
  44. set(gca, 'xticklabel',{ '1', '2', '3', '4'});

由于写论文需要,所以实现了下柱状图的实现实现代码如下,实现效果如下图。

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值