Skip to content
Extraits de code Groupes Projets
bar_plot.py 1,59 ko
Newer Older
  • Learn to ignore specific revisions
  • #!/usr/bin/env python3
    #  -*- coding: utf-8 -*-
    
    """
    Reads data of oil spill arrival time from shipping routes to different sites and computes its monthly mean and standard deviation
    
    Author: Thomas Dobbelaere, Earth and Life Institute, UCLouvain, Belgium
    Last modified: 19 July 2022
    """
    import matplotlib.pyplot as plt
    import numpy as np
    from matplotlib import pyplot
    import calendar
    import matplotlib as mpl
    
    months = [calendar.month_abbr[i] for i in range(1,13)]
    
    fd = np.load("arrival_by_route.npy", allow_pickle=True).item()
    routes = fd["routes"]
    meanv = np.nanmean(fd["data"], axis=2)
    stdv = np.nanstd(fd["data"], axis=2)
    route_names = {
        "Barhain" : "Barhain",
        "Iran" : "Qatar-Iran",
        "Ras_laffan_field": 'Ras Laffan to North Field',
        "Ras_laffan": "Ras Laffan LNG export",
        "Doha" : 'Doha-Mesaieed'
    }
    x = np.arange(len(months))
    width = 0.18
    offset = np.arange(-2,3)*width
    clrs = mpl.cm.Reds_r(0.1 + 0.8*np.linspace(0,1,5))
    
    fig, ax = plt.subplots(figsize=(14,7))
    ibar = 0
    for key,label in route_names.items():
        row = routes.index(key)
        ax.bar( x+offset[ibar], meanv[row], width=width, yerr=stdv[row], \
                    color=clrs[ibar], ecolor="k", capsize=3, label=label)
        ibar += 1
    
    ax.set_ylabel('Mean arrival time (days)', fontsize=14)
    ax.set_yticklabels((0,1,2,3,4),fontsize=14)
    ax.set_xticks(x)
    ax.set_xticklabels(months, fontsize=14)
    ax.spines['top'].set_visible(False) 
    ax.spines['right'].set_visible(False)
    for i in range(1,5):
        ax.axhline(y=i, color='grey', linestyle=(0, (2, 10)))
    ax.legend(loc=1, fontsize=12)
    
    plt.savefig('mean_arrival_by_route.png', bbox_inches='tight', dpi=200)