当前位置:   article > 正文

画黑白带阴影线的柱状图(论文专用)_科学论文,柱状图,条纹hatch

科学论文,柱状图,条纹hatch

Matplotlib代码:

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from pylab import *
  4. mpl.rcParams['font.sans-serif']=['SimHei']
  5. def read():
  6. name_list = ['计算机'.decode("utf-8"),'法律'.decode("utf-8"),'文学'.decode("utf-8"),'医学'.decode("utf-8"),'体育'.decode("utf-8")]
  7. # name_list = ['引言','相关工作','数据','方法','实验','结果','讨论']
  8. time1=[0.913,0.465,0.512,0.553,0.779]
  9. time2=[0.072,0.465,0.268,0.415,0.162]
  10. time3=[0.014,0.070,0.146,0.011,0.044]
  11. time4=[0.000,0.000,0.073,0.021,0.015]
  12. location=np.arange(len(name_list))
  13. width=0.2
  14. plt.figure(figsize=(12,4))
  15. plt.bar(location, time1,tick_label = name_list,width = width,label="1",alpha=0.8,color="w",edgecolor="k")
  16. for a,b in zip(location, time1):
  17. plt.text(a, b+0.05, '%.3f' % b, ha='center', va= 'bottom',fontsize=7)
  18. plt.bar(location+width, time2,tick_label = name_list,width = width,label="1-2",alpha=0.8,color="w",edgecolor="k",hatch=".....")
  19. for a,b in zip(location+width, time2):
  20. plt.text(a, b+0.05, '%.3f' % b, ha='center', va= 'bottom',fontsize=7)
  21. plt.bar(location+width*2, time3,tick_label = name_list,width = width,label="2-3",alpha=0.8,color="w",edgecolor="k",hatch="/")
  22. for a,b in zip(location+width*2, time3):
  23. plt.text(a, b+0.05, '%.3f' % b, ha='center', va= 'bottom',fontsize=7)
  24. plt.bar(location+width*3, time4,tick_label = name_list,width = width,label=">3",alpha=0.8,color="w",edgecolor="k",hatch="\\\\\\\\\\")
  25. for a,b in zip(location+width*3, time4):
  26. plt.text(a, b+0.05, '%.3f' % b, ha='center', va= 'bottom',fontsize=7)
  27. plt.ylim(0,1)
  28. plt.legend(loc=1)
  29. plt.show()
  30. if __name__ == '__main__':
  31. read()

Matlab代码:

 在科技文献写作等过程中,我们往往需要粘贴柱状图或者条形图,图中以不同颜色对不同数据进行区分,然而当黑白打印时,色彩颜色往往难以区分,故而需要绘制带有黑白阴影的柱状图或者条形图。对比效果见图1。下面介绍具体实现方法,本程序主体由Ben Hinkle完成,我只是个中间搬运工。

图1 

 

顶层代码与分析如下,完整代码见链接:https://download.csdn.net/download/u013608300/10364534

https://pan.baidu.com/s/1NqzRupJMD4Dka57MJrxJng

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/133087
推荐阅读