import scipy.io
import numpy as np
import matplotlib.pylab as pylab
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
params={
'axes.labelsize': '35',
'xtick.labelsize':'27',
'ytick.labelsize':'27',
'lines.linewidth':2 ,
'legend.fontsize': '27',
'figure.figsize': '24, 9'
}
pylab.rcParams.update(params)y1 = [9.79,7.25,7.24,4.78,4.20]
y2 = [5.88,4.55,4.25,3.78,3.92]
y3 = [4.69,4.04,3.84,3.85,4.0]
y4 = [4.45,3.96,3.82,3.80,3.79]
y5 = [3.82,3.89,3.89,3.78,3.77]ind = np.arange(5)# the x locations for the groups
width = 0.15
plt.bar(ind,y1,width,color = 'blue',label = 'm=2')#x设置了5个值
plt.bar(ind+width,y2,width,color = 'g',label = 'm=4') # ind+width adjusts the left start location of the bar.
plt.bar(ind+2*width,y3,width,color = 'c',label = 'm=6')
plt.bar(ind+3*width,y4,width,color = 'r',label = 'm=8')
plt.bar(ind+4*width,y5,width,color = 'm',label = 'm=10')
#画x,y总共5个bar值
plt.xticks(np.arange(5) + 2.5*width, ('10%','15%','20%','25%','30%'))#画x的标签
#设置x的标签
plt.xlabel('Sample percentage')
plt.ylabel('Error rate')fmt = '%.0f%%' # Format you want the ticks, e.g. '40%'
xticks = mtick.FormatStrFormatter(fmt)# Set the formatter
axes = plt.gca()# get current axes
axes.yaxis.set_major_formatter(xticks) # set % format to ystick.
axes.grid(True)
plt.legend(loc="upper right")
plt.savefig('plot_test2bar.png',dpi = 1000,bbox_inches='tight')plt.show()
【python|Python 画图,柱状图】
文章图片
推荐阅读
- python|Python 画图,点线图
- IT|Python开发学习之Python和Excel的数据实现互通
- machine|GridSearchCV调参方法
- PHP与Python有什么区别和不同()
- 发现几个好玩的游戏编程平台,与君共勉!
- 机器学习|Python实现词云舞
- python相关学习|用python批量修改图片名称!超级简单
- 大数据|超高分辨率显著目标检测,新颖高效的错层嫁接架构PGNet(CVPR2022)
- 编程语言大杂烩|Python批量改变图片名字