使用 matplotlib 绘制western blot表达量柱状图

素闻Python  matplotlib 绘图功能强大,特地在网上搜索资源尝试了一下,综合各位大神的笔记,编写了一个绘制western blot表达量柱状图的小程序


#!coding:utf-8
import numpy as np #导入numpy函数  
import matplotlib.pyplot as plt  #导入matplotlib函数

n_groups = 3  #设定初始值
zh = [1, 1,1 ]  #数据1  
fh = [3.20,3.88,3.64] #数据2
eh = [2.9,4.7,3.65]
err1 = [0,0,0] #数据1的标准差
err2 = [0.44,0.38,0.32]  #数据2的标准差
err3 = [0.38,0.33,0.61]
ax = plt.subplot(1,1,1)  #设定图像长宽高
ax.spines['right'].set_visible(True)  #Flase为取消右侧线条
ax.spines['top'].set_visible(True)  #Flase为取消顶部线条
ax.spines['bottom'].set_linewidth(1.5)  #设置x轴的粗细
ax.spines['left'].set_linewidth(1.5)  #设置y轴的粗细
index = np.arange(n_groups)  #生成【0,1,2,3,4】数组
bar_width = 0.2  #柱状图宽度
opacity = 0.5   #透明度
rects1 = plt.bar(index, zh, bar_width,yerr=err1,capsize=8,alpha=opacity, color='k',ls='-', lw=1,ec='k') #rects1 = plt.bar(i
ndex (x轴位置), means_men(y轴位置), bar_width(柱状图宽度),yerr=err1(误差),capsize=8(误差顶端横杠),alpha=opacity(透明度), color='b'(柱状图颜色),ls='-'(柱状图外围线), lw=1(线宽度),ec='k'(线颜色)ecolor = ‘"r"误差线颜色

rects2 = plt.bar(index + bar_width, fh,bar_width,yerr=err2,capsize=8,alpha=opacity,color='b',ls='-', lw=1,ec='k')
rects3 = plt.bar(index + 2*bar_width, eh,bar_width,yerr=err3,capsize=8,alpha=opacity,color='r',ls='-', lw=1,ec='k')
plt.legend(labels = ['Guy11',r'$\Delta$''MoVps9',r'$\Delta$''MoVps9'r'$\Delta$''MoMuk1' ],fontsize = 12,loc = 'upper right')
#(labels(图例) = ['men'(图例1),'women'(图例2)],fontsize = 12(图例大小),loc = 'upper right'(图例位置))
plt.xlabel('',fontsize = 17)  #横坐标标签 字体大小
plt.ylabel('MoATG8 related expression',fontsize = 17)  #纵坐标标签 字体类型 大小
plt.xticks(index+bar_width,('0h', '4h', '8h',),fontsize = 17)  #图表x坐标值 为了让坐标值在中间,数组加柱状图的1/2, 字体大小
  

plt.ylim(0,7)   #纵坐标的取值范围
plt.tight_layout()  #紧凑图表
plt.show()  #显示图表

#使用 matplotlib 绘制western blot表达量柱状图