def example_calc_histogram_plot_barchart(datafile, output_file=None):
    """An example of calulating a histogram and then plotting the result.
    
    datafile    the path to the file to plot
    output_file path to the graph picture file to produce

    """

    data = cxh.calc_xy_histogram(datafile, bins=50)
    pb.plot_barchart(data, output_file=output_file,
                     title='example_calc_histogram_plot_barchart',
                     xlabel='IQ', ylabel='frequency',
                     xrange=None, yrange=None, grid=True,
                     show_graph=True, annotate=[])
Пример #2
0
def example_calc_histogram_plot_barchart(datafile, output_file=None):
    """An example of calulating a histogram and then plotting the result.
    
    datafile    the path to the file to plot
    output_file path to the graph picture file to produce

    """

    data = cxh.calc_xy_histogram(datafile, bins=50)
    pb.plot_barchart(data,
                     output_file=output_file,
                     title='example_calc_histogram_plot_barchart',
                     xlabel='IQ',
                     ylabel='frequency',
                     xrange=None,
                     yrange=None,
                     grid=True,
                     show_graph=True,
                     annotate=[])
def plot_scen_loss_stats(input_dir, site_tag, output_dir,
#                         plot_file, save_file=None,
                         pre89=False, dollars89=False, resonly=False):
    """Plot a scenario loss statistics graph from scenario data.

    input_dir  input directory
    site_tag   event descriptor string
    output_dir general output directory
##    plot_file  name of map output file to create in 'output_dir' directory
##    save_file  name of map data output file to create in 'output_dir' directory
    pre89      if True consider buildings that existed before 1989 only
    dollars89  if True express dollar values in pre-1989 dollars
    resonly    if True consider only residential buildings

    """

    # read in raw data
    data = cpr.obsolete_convert_Py2Mat_Risk(site_tag)

    # filter data depending on various flags
    temp_ecloss = data.ecloss
    temp_bval2 = data.ecbval2
    
    if pre89:
        if resonly:
            take_array = [x[2] and x[11] for x in data.structures]
            temp_ecloss = scipy.take(data.ecloss, take_array)
            temp_bval2 = scipy.take(data.ecbval2, take_array)
        else:
            take_array = [x[2] for x in data.structures]
            temp_ecloss = scipy.take(data.ecloss, take_array)
            temp_bval2 = scipy.take(data.ecbval2, take_array)
    else:
        if resonly:
            take_array = [x[11] == 'RES1' for x in data.structures]
            temp_ecloss = scipy.take(data.ecloss, resonly_array)
            temp_bval2 = scipy.take(data.ecbval2, resonly_array)
        else:
            temp_ecloss = data.ecloss
            temp_bval2 = data.ecbval2

    # which dollars does user want
    doll_str = 'in 2002 dollars'
    cvt_doll = 1.0
    if dollars89:
        doll_str = 'in 1989 dollars'
        cvt_doll = 1/1.37

    f_ecloss = cvt_doll * temp_ecloss
    f_bval2 = cvt_doll * temp_bval2

    f_aggloss_bill = scipy.sum(f_bval2) / 1e9
    
    print('f_ecloss=%s' % str(f_ecloss))
    print('f_bval2=%s' % str(f_bval2))
    print('f_aggbval2_bill=%s' % str(f_aggloss_bill))

    h_data = cxh.calc_xy_histogram(f_aggloss_bill, bins=10)
    plot_out = os.path.join(output_dir, 'test1.png')
    title = 'Newc89 agg loss, pre89, 1989 dollars'
    xlabel = '$ %s (x 1e+9)' % doll_str
    pb.plot_barchart(h_data, output_file=plot_out, title=title,
                     xlabel=xlabel, ylabel='frequency',
                     xrange=None, yrange=None, grid=True,
                     show_graph=True, annotate=[])