Example #1
0
def plot_missing_values(data, data_gaps, data_column='', title='', var_name='', var_unit='', fig_filename='',
                        circular=False, label='observations'):
    # Get style
    plot.get_default_plot_style()
    # Get values
    values = plot.get_values(data, data_column)
    # Get var label
    var_label = plot.get_var_label(var_name, var_unit)
    # Plot
    ax = plt.axes()
    ax.plot(values.index, values, ':', alpha=0.3, label=label)
    ax.plot(values.loc[data_gaps.loc[:, 'pos_ini']], '.k', markersize=10, label='Gaps_initial_postion')
    ax.plot(values.loc[data_gaps.loc[:, 'pos_fin']], '.r', markersize=10, label='Gaps_final_postion')
    ax.legend(loc='upper right', facecolor='white')
    plot.plot_title(ax, title)

    if circular is True:
        circular_labels, circular_ticks = plot.get_circular_ticks()
        plt.yticks(circular_ticks, circular_labels)

    ax.set_ylabel(var_label)
    # fixing the x tick labels are all squashed together
    plt.gcf().autofmt_xdate()

    plot.save_figure(fig_filename)
Example #2
0
def plot_histogram(data,
                   title='',
                   var_name='',
                   var_unit='',
                   fig_filename='',
                   rug=False,
                   data_column='',
                   circular=False,
                   kernel=False,
                   bins='auto'):
    plot.get_default_plot_style()

    values = plot.get_values(data, data_column)
    var_label = plot.get_var_label(var_name, var_unit)

    # Remove null values
    values_clean = values.dropna(axis=0, how='all')
    ax = sns.distplot(values_clean,
                      rug=rug,
                      hist_kws={'edgecolor': 'black'},
                      kde=kernel,
                      bins=bins,
                      norm_hist=True)

    plot.plot_title(ax, title)

    if circular:
        circular_labels, circular_ticks = plot.get_circular_ticks()
        plt.xticks(circular_ticks, circular_labels)

    ax.set_xlabel(var_label)

    plot.save_figure(fig_filename)
Example #3
0
def peaks_plot(data,
               peaks,
               data_column='',
               title='',
               var_name='',
               var_unit='',
               fig_filename='',
               circular=False,
               data_label='',
               peaks_label=''):
    # Get style
    plot.get_default_plot_style()
    # Get values
    values = plot.get_values(data, data_column)
    # Get var label
    var_label = plot.get_var_label(var_name, var_unit)
    # Plot
    ax = plt.axes()
    ax.plot(values.index, values, ':', alpha=0.3, label=data_label)
    # ax.plot(peaks.index, peaks, '.r', markersize=10, label=peaks_label)
    ax.legend(loc='upper right', facecolor='white')
    plot.plot_title(ax, title)

    if circular:
        circular_labels, circular_ticks = plot.get_circular_ticks()
        plt.yticks(circular_ticks, circular_labels)

    ax.set_ylabel(var_label)
    # fixing the x tick labels are all squashed together
    plt.gcf().autofmt_xdate()
    plt.xlim([1959, 2018])

    plot.save_figure(fig_filename)
Example #4
0
def plot_kde(data_empirical,
             data_kernel,
             cumulative,
             title='',
             var_name='',
             var_unit='',
             fig_filename='',
             circular=False,
             label_empirical='',
             label_kernel=''):

    plot.get_default_plot_style()

    values_empirical = plot.get_values(data_empirical, '')
    var_label = plot.get_var_label(var_name, var_unit)

    ax = plt.axes()
    ax.plot(values_empirical.index, values_empirical, label=label_empirical)
    if cumulative:
        values_kernel = plot.get_values(data_kernel, '')
        ax.plot(values_kernel.index, values_kernel, label=label_kernel)
    ax.legend(loc='upper right', facecolor='white')

    plot.plot_title(ax, title)

    if circular:
        circular_labels, circular_ticks = plot.get_circular_ticks()
        plt.yticks(circular_ticks, circular_labels)

    plot.plot_title(ax, title)
    ax.set_xlabel(var_label)

    if cumulative:
        ax.set_ylabel('CDF')
    else:
        ax.set_ylabel('PDF')

    # fixing the x tick labels are all squashed together
    plt.gcf().autofmt_xdate()

    plot.save_figure(fig_filename)
Example #5
0
def plot_series(data,
                title='',
                var_name='',
                var_unit='',
                fig_filename='',
                data_column='',
                circular=False,
                show_trends=False,
                label='observations'):
    plot.get_default_plot_style()

    values = plot.get_values(data, data_column)
    var_label = plot.get_var_label(var_name, var_unit)

    ax = plt.axes()
    if show_trends is False:
        ax.plot(values.index, values, linewidth=0.5)
    else:
        # TODO Comprobar que funciona correctamente con más ejemplos

        # UnivariateSpline needs conversion from DateTimeIndex to float
        splined_index = values.index.values.astype('d')
        splined_values = UnivariateSpline(splined_index, values)

        ax.plot(values.index, values, ':', alpha=0.3, label=label)
        ax.plot(values.index, splined_values(splined_index))

        ax.legend(loc='upper right', facecolor='white')

    plot.plot_title(ax, title)

    if circular:
        circular_labels, circular_ticks = plot.get_circular_ticks()
        plt.yticks(circular_ticks, circular_labels)

    ax.set_ylabel(var_label)
    # fixing the x tick labels are all squashed together
    plt.gcf().autofmt_xdate()

    plot.save_figure(fig_filename)
Example #6
0
def plot_ecdf_sm_dots(data,
                      title='',
                      var_name='',
                      var_unit='',
                      fig_filename='',
                      data_column='',
                      label='Observations'):
    plot.get_default_plot_style()

    values = plot.get_values(data, data_column)
    var_label = plot.get_var_label(var_name, var_unit)

    ax = plt.axes()
    ax.plot(values.index, values, '.', label=label)
    ax.legend(loc='upper right', facecolor='white')
    plot.plot_title(ax, title)

    ax.set_xlabel(var_label)
    # fixing the x tick labels are all squashed together
    plt.gcf().autofmt_xdate()

    plt.show()
    plot.save_figure(fig_filename)