赞
踩
Matplotlib代码:
- import numpy as np
- import matplotlib.pyplot as plt
- from pylab import *
- mpl.rcParams['font.sans-serif']=['SimHei']
- def read():
- name_list = ['计算机'.decode("utf-8"),'法律'.decode("utf-8"),'文学'.decode("utf-8"),'医学'.decode("utf-8"),'体育'.decode("utf-8")]
- # name_list = ['引言','相关工作','数据','方法','实验','结果','讨论']
- time1=[0.913,0.465,0.512,0.553,0.779]
- time2=[0.072,0.465,0.268,0.415,0.162]
- time3=[0.014,0.070,0.146,0.011,0.044]
- time4=[0.000,0.000,0.073,0.021,0.015]
-
- location=np.arange(len(name_list))
- width=0.2
-
- plt.figure(figsize=(12,4))
- plt.bar(location, time1,tick_label = name_list,width = width,label="1",alpha=0.8,color="w",edgecolor="k")
- for a,b in zip(location, time1):
- plt.text(a, b+0.05, '%.3f' % b, ha='center', va= 'bottom',fontsize=7)
- plt.bar(location+width, time2,tick_label = name_list,width = width,label="1-2",alpha=0.8,color="w",edgecolor="k",hatch=".....")
- for a,b in zip(location+width, time2):
- plt.text(a, b+0.05, '%.3f' % b, ha='center', va= 'bottom',fontsize=7)
- plt.bar(location+width*2, time3,tick_label = name_list,width = width,label="2-3",alpha=0.8,color="w",edgecolor="k",hatch="/")
- for a,b in zip(location+width*2, time3):
- plt.text(a, b+0.05, '%.3f' % b, ha='center', va= 'bottom',fontsize=7)
- plt.bar(location+width*3, time4,tick_label = name_list,width = width,label=">3",alpha=0.8,color="w",edgecolor="k",hatch="\\\\\\\\\\")
- for a,b in zip(location+width*3, time4):
- plt.text(a, b+0.05, '%.3f' % b, ha='center', va= 'bottom',fontsize=7)
-
- plt.ylim(0,1)
- plt.legend(loc=1)
- plt.show()
-
- if __name__ == '__main__':
- read()
Matlab代码:
在科技文献写作等过程中,我们往往需要粘贴柱状图或者条形图,图中以不同颜色对不同数据进行区分,然而当黑白打印时,色彩颜色往往难以区分,故而需要绘制带有黑白阴影的柱状图或者条形图。对比效果见图1。下面介绍具体实现方法,本程序主体由Ben Hinkle完成,我只是个中间搬运工。
图1
顶层代码与分析如下,完整代码见链接:https://download.csdn.net/download/u013608300/10364534
https://pan.baidu.com/s/1NqzRupJMD4Dka57MJrxJng
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。