Ejemplo n.º 1
0
def plot_data(data, i_array, j_array, name='AEX', title = None, digits = 1,
                                      color_map = mpl.cm.get_cmap('RdBu'),
                                      minmax = (None, None),
                                      units = '%',
                                      colorbar_orientation = 'vertical'
                                      ):



    if name != None:
        plt.figure()

    to_plot = np.ma.masked_all(xs.shape)
    for index, i, j in zip( range(len(data)), i_array, j_array):
        to_plot[i, j] = data[index]


    print np.ma.min(data), np.ma.max(data)

  #  m.pcolor(xs, ys, to_plot, cmap = mpl.cm.get_cmap('RdBu_r'))

    extent = [np.min(xs), np.max(xs), np.min(ys), np.max(ys)]
    plt.imshow(to_plot.transpose().copy(), interpolation = 'nearest' ,
                                    extent = extent,
                                    origin = 'lower',
                                    cmap = color_map,
                                    vmin = minmax[0],
                                    vmax = minmax[1]
                                    )


    plot_basin_boundaries_from_shape(m, linewidth = 1)
    m.drawrivers()
    m.drawcoastlines()
    draw_meridians_and_parallels(m, step_degrees = 30)

    int_ticker = LinearLocator()
    cb = plt.colorbar(ticks = int_ticker, orientation = colorbar_orientation)
    cb.ax.set_ylabel(units)

    override = {'fontsize': 20,
                  'verticalalignment': 'baseline',
                  'horizontalalignment': 'center'}


    plt.title(title if title != None else name, override)

    ymin, ymax = plt.ylim()
    plt.ylim(ymin + 0.12 * (ymax - ymin), ymax * 0.32)

    xmin, xmax = plt.xlim()
    plt.xlim(xmin + (xmax - xmin) * 0.65, 0.85*xmax)

    if name != None:
        plt.savefig(name + '.png', bbox_inches = 'tight')
def plot_forcing_error(errors_map, i_list, j_list):
    pylab.rcParams.update(params)
    to_plot = ma.masked_all(xs.shape)

    err = None
    for id, error in errors_map.iteritems():
        if err == None:
            err = np.zeros(error.shape)
        err += error

    err = err / len(errors_map)

    for i, j, er in zip(i_list, j_list, err):
        to_plot[i,j] = er



    n_levels = 20
    plt.imshow(to_plot.transpose().copy(), extent = [np.min(xs), np.max(xs), ys.min(), ys.max()],
                                        origin = 'lower',
                                        interpolation = 'bilinear' ,
                                        cmap = mpl.cm.get_cmap('RdBu_r', n_levels),
                                        vmin = -30, vmax = 30)

    int_ticker = MaxNLocator(nbins=n_levels, integer=True)
    cb = plt.colorbar(ticks = int_ticker)
    cb.ax.set_ylabel('%')

    basemap.drawcoastlines()
    print np.min(lons), np.max(lons), lats.min(), lats.max()

    plot_basin_boundaries_from_shape(basemap, linewidth = 0.5)

    ymin, ymax = plt.ylim()
    plt.ylim(ymin + 0.12 * (ymax - ymin), ymax * 0.32)

    xmin, xmax = plt.xlim()
    plt.xlim(xmin + (xmax - xmin) * 0.65, 0.85*xmax)
    draw_meridians_and_parallels(basemap, 10)
    plt.savefig("forcing_errors.png")
def plot_forcing_errors(errors_map, i_list, j_list):
    pylab.rcParams.update(params)
    num_plots = len(errors_map)
    nrows = int(round(num_plots / 2.0))
    k = 1
    to_plot = ma.masked_all(xs.shape)


    plt.subplots_adjust(left = 0., right = 0.98, wspace = 0, hspace = 0.2)
    for id, errors in errors_map.iteritems():
        print '------------------------------'
        print id
        print k


        plt.subplot(2, nrows, k)
        plt.title(id.upper())
        for i, j, er in zip(i_list, j_list, errors):
            to_plot[i,j] = er

#        dx = 45000.0
#        basemap.pcolor(xs - dx / 2.0 , ys - dx / 2.0, to_plot, shading='gouraud',
#                          lw = 0,
#                          vmin = -30, vmax = 30,
#                          cmap = mpl.cm.get_cmap('RdYlBu_r'))



      
        
        plt.imshow(to_plot.transpose().copy(), extent = [np.min(xs), np.max(xs), ys.min(), ys.max()],
                                        origin = 'lower',
                                        interpolation = 'bilinear' ,
                                        cmap = mpl.cm.get_cmap('RdBu_r'),
                                        vmin = -30, vmax = 30)



        int_ticker = MaxNLocator(nbins=6, integer=True)


        cb = plt.colorbar(ticks = int_ticker)
        cb.ax.set_ylabel('%')

        basemap.drawcoastlines()
        print np.min(lons), np.max(lons), lats.min(), lats.max()
        
        

        plot_basin_boundaries_from_shape(basemap, linewidth = 0.5)
        
        ymin, ymax = plt.ylim()
        plt.ylim(ymin + 0.12 * (ymax - ymin), ymax * 0.32)



        xmin, xmax = plt.xlim()
        plt.xlim(xmin + (xmax - xmin) * 0.65, 0.85*xmax)



       

        
  #      plt.ylabel('( %s - aex ) /(0.5(%s + aex))' % (id,id) + '  (%)', size = 12)


        k += 1

    
    plt.savefig("forcing_errors.png")