Ejemplo n.º 1
0
def wind_rose(freqs,
              sectors=12,
              title='Wind Rose',
              color=None,
              all_ticks=False):
    '''
    Plots a wind rose using sectorwise frequencies

    Parameters:
    ___________
    freqs: numpy array, list, or pandas series of float or int
        Array of frequencies to plot for wind rose
    sectors: int
        Number of sectors to plot. Must be the same as len(freqs) to
        avoid error
    title: string
        Plot title
    color: string, default None
        Plot color, from standard matplotlib color library
    all_ticks: boolean, default False
        Enabling this parameter will plot ticks for every sector. Otherwise,
        only 30 degree ticks are plotted

    Returns:
    ________
    Wind rose plot
    '''

    #Set up binned frequencies and labels
    bins = 360 / sectors
    theta = np.arange(0, 360, bins)
    theta_rad = theta * math.pi / 180
    if all_ticks:
        ticklabs = [str(x) for x in theta]
        ticks = theta
    else:
        ticklabs, ticks = np.arange(0, 360, 30), np.arange(0, 360, 30)

    #Plot, with N correctly oriented
    fig = plt.figure(figsize=(8, 8))
    ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True)
    ax.set_theta_zero_location('N')
    ax.set_theta_direction(-1)
    ax.set_thetagrids(ticks, labels=ticklabs)
    ax.set_title(title)
    ax.grid(True, 'major', color='w', linestyle='-', linewidth=0.7)
    ax.patch.set_facecolor('0.90')
    ax.set_axisbelow(True)
    width = bins * math.pi / 180
    adj_theta = theta_rad - width / 2
    stylers.rbar(ax,
                 adj_theta,
                 freqs,
                 width=width,
                 bottom=0.0,
                 alpha=0.7,
                 color=color)
Ejemplo n.º 2
0
def wind_rose(freqs, sectors=12, title='Wind Rose', color=None,
              all_ticks=False):
    '''
    Plots a wind rose using sectorwise frequencies

    Parameters:
    ___________
    freqs: numpy array, list, or pandas series of float or int
        Array of frequencies to plot for wind rose
    sectors: int
        Number of sectors to plot. Must be the same as len(freqs) to
        avoid error
    title: string
        Plot title
    color: string, default None
        Plot color, from standard matplotlib color library
    all_ticks: boolean, default False
        Enabling this parameter will plot ticks for every sector. Otherwise,
        only 30 degree ticks are plotted

    Returns:
    ________
    Wind rose plot
    '''

    #Set up binned frequencies and labels
    bins = 360/sectors
    theta = np.arange(0, 360, bins)
    theta_rad = theta*math.pi/180
    if all_ticks:
        ticklabs = [str(x) for x in theta]
        ticks = theta
    else:
        ticklabs, ticks = np.arange(0, 360, 30), np.arange(0, 360, 30)

    #Plot, with N correctly oriented
    fig = plt.figure(figsize=(8, 8))
    ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True)
    ax.set_theta_zero_location('N')
    ax.set_theta_direction(-1)
    ax.set_thetagrids(ticks, labels=ticklabs)
    ax.set_title(title)
    ax.grid(True, 'major', color='w', linestyle='-', linewidth=0.7)
    ax.patch.set_facecolor('0.90')
    ax.set_axisbelow(True)
    width = bins*math.pi/180
    adj_theta = theta_rad-width/2
    stylers.rbar(ax, adj_theta, freqs, width=width, bottom=0.0, alpha=0.7,
                 color=color)
Ejemplo n.º 3
0
def weibull(x, dist, binned=False, binned_x=None, binned_data=None, **kwargs):
    '''
    Plots a weibull distribution, both the pdf and binned values

    Parameters:
    ___________
    x: array of float or int
        x-axis array, independent axis
    dist: scipy.stats pdf
        pdf of distribution, generated by scipy.stats
    binned: boolean, default False
        True if you want to plot both the continuous distribution and
        the hourly distribution
    binned_x: array of float or int, default None
        x-axis array for binned data, optional
    binned_data: array of float or int, default none
        binned data, to plot over pdf

    Returns:
    ________
    Plot of weibull distribution
    '''

    fig, ax1 = plt.subplots()
    ax2 = None

    if binned:
        bin_width = binned_x[1] - binned_x[0]
        stylers.rbar(ax1, binned_x, binned_data, width=bin_width, **kwargs)
        stylers.rstyle(ax1)
        ax1.set_xlabel(r'Wind Speed [m/s]', fontsize=12)
        ax1.set_ylabel(r'Hours', fontsize=12)
        ax2 = ax1.twinx()

    if ax2:
        pdfax = ax2
    else:
        pdfax = ax1

    pdfax.set_xlim((0, 40))
    stylers.rfill(
        pdfax,
        x,
        dist,
    )
    if not ax2:
        stylers.rstyle(pdfax)
    pdfax.set_ylabel(r'PDF', fontsize=12)
Ejemplo n.º 4
0
def weibull(x, dist, binned=False, binned_x=None, binned_data=None, **kwargs):
    '''
    Plots a weibull distribution, both the pdf and binned values

    Parameters:
    ___________
    x: array of float or int
        x-axis array, independent axis
    dist: scipy.stats pdf
        pdf of distribution, generated by scipy.stats
    binned: boolean, default False
        True if you want to plot both the continuous distribution and
        the hourly distribution
    binned_x: array of float or int, default None
        x-axis array for binned data, optional
    binned_data: array of float or int, default none
        binned data, to plot over pdf

    Returns:
    ________
    Plot of weibull distribution
    '''

    fig, ax1 = plt.subplots()
    ax2 = None

    if binned:
        bin_width = binned_x[1]-binned_x[0]
        stylers.rbar(ax1, binned_x, binned_data, width=bin_width, **kwargs)
        stylers.rstyle(ax1)
        ax1.set_xlabel(r'Wind Speed [m/s]', fontsize=12)
        ax1.set_ylabel(r'Hours', fontsize=12)
        ax2 = ax1.twinx()

    if ax2:
        pdfax = ax2
    else:
        pdfax = ax1

    pdfax.set_xlim((0, 40))
    stylers.rfill(pdfax, x, dist,)
    if not ax2:
        stylers.rstyle(pdfax)
    pdfax.set_ylabel(r'PDF', fontsize=12)