并列柱形图的绘制代码

并列柱形图的绘制

import matplotlib.pyplot as plt

plt.style.use('seaborn-whitegrid')
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['font.sans-serif']=['Times New Roman']#设置为新罗马字体(其他电脑系统未安装对应字体,可能会报错)
plt.rcParams['axes.unicode_minus'] = False
fig = plt.figure(figsize=(100, 30),dpi=50)
for i,name in enumerate(['拖网','围网','刺网','张网','钓业']):
    data_S = data[data['作业类型'] == name].copy()
    #记得循环k
    ax = fig.add_subplot(1,5,i+1)
    ax.spines['bottom'].set_linewidth('1.0')#设置边框线宽为2.0
    ax.spines['bottom'].set_color('black')
    ax.spines['top'].set_linewidth('1.0')#设置边框线宽为2.0
    ax.spines['top'].set_color('black')
    ax.spines['right'].set_linewidth('1.0')#设置边框线宽为2.0
    ax.spines['right'].set_color('black')
    ax.spines['left'].set_linewidth('1.0')#设置边框线宽为2.0
    ax.spines['left'].set_color('black')
    plt.xticks(fontsize = 20)
    plt.yticks(fontsize = 20)
    mincolor=(42/256,87/256,141/256,0/3)#最后一个数字是透明度,前三个是三基色
    midcolor=(42/256,87/256,141/256,0/3)
    index=numpy.arange(len(data_S))
    plt.bar(
        index,
        data_S['Initial carbon quantity(Ton)'],
        color=mincolor,edgecolor='black',
        width=1/3,label = 'Initial carbon quantity(Ton)',hatch='/\\')
    plt.bar(
        index+1/3,
        data_S['Adjusted carbon quantity(Ton)'],
        color=midcolor,edgecolor='black',
        width=1/3,label = 'Adjusted carbon quantity(Ton)',hatch='//')
    plt.xticks(index+1/6,data_S['name_english'])
    # https://blog.csdn.net/mighty13/article/details/113869911

  #  plt.ylim(2.5,100)
  #  plt.xlim(0, 100)
    plt.xticks(size=45,rotation = 40)
    plt.yticks(size=40)
    plt.title(data_S.iloc[0,-2],size=50)
lines, labels = fig.axes[-1].get_legend_handles_labels()
fig.legend(lines, labels,loc='upper center', bbox_to_anchor=(0.5, 0.05), ncol=3,fontsize = 50)#设置公共的图例
# https://blog.csdn.net/lzw790222124/article/details/121574695

plt.savefig('论文使用——英文.png',dpi = 300,pad_inches=0.1)

猜你喜欢

转载自blog.csdn.net/qq_42830971/article/details/127433350