当前位置: 首页>>代码示例>>Python>>正文


Python MapPlot.contourf方法代码示例

本文整理汇总了Python中pyiem.plot.MapPlot.contourf方法的典型用法代码示例。如果您正苦于以下问题:Python MapPlot.contourf方法的具体用法?Python MapPlot.contourf怎么用?Python MapPlot.contourf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyiem.plot.MapPlot的用法示例。


在下文中一共展示了MapPlot.contourf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: do_month

# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import contourf [as 别名]
def do_month(ts, routes='m'):
    """
    Generate the plot for a given month, please
    """
    sql = """SELECT station, sum(precip) as total, max(day) as lastday
           from alldata_ia WHERE year = %s and month = %s
           and station != 'IA0000' and substr(station,2,1) != 'C'
           GROUP by station""" % (ts.year, ts.month)

    lats = []
    lons = []
    vals = []
    lastday = None
    ccursor.execute(sql)
    for row in ccursor:
        if row['station'] not in nt.sts:
            continue
        if lastday is None:
            lastday = row['lastday']
        lats.append(nt.sts[row['station']]['lat'])
        lons.append(nt.sts[row['station']]['lon'])
        vals.append(row['total'])

    m = MapPlot(title='%s - %s' % (ts.strftime("%d %B %Y"),
                                   lastday.strftime("%d %B %Y")),
                subtitle="%s Total Precipitation [inch]" % (
                                    ts.strftime("%B %Y"),))
    m.contourf(lons, lats, vals, [0, 0.1, 0.25, 0.5, 0.75, 1, 2, 3, 4, 5, 6,
                                  7])
    m.plot_values(lons, lats, vals, fmt='%.2f')

    pqstr = ("plot %s %s summary/iemre_iowa_total_precip.png "
             "%s/summary/iemre_iowa_total_precip.png png"
             ) % (routes, ts.strftime("%Y%m%d%H%M"), ts.strftime("%Y/%m"))
    m.postprocess(pqstr=pqstr)
开发者ID:muthulatha,项目名称:iem,代码行数:37,代码来源:plot_monthly_precip.py

示例2: plotter

# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import contourf [as 别名]
def plotter(fdict):
    """ Go """
    import matplotlib
    matplotlib.use('agg')
    from pyiem.plot import MapPlot
    import matplotlib.cm as cm

    pgconn = psycopg2.connect(database='coop', host='iemdb', user='nobody')
    cursor = pgconn.cursor()

    sector = fdict.get('sector', 'IA')
    date1 = datetime.datetime.strptime(fdict.get('date1', '2015-01-01'),
                                       '%Y-%m-%d')
    date2 = datetime.datetime.strptime(fdict.get('date2', '2015-02-01'),
                                       '%Y-%m-%d')

    table = "alldata_%s" % (sector, ) if sector != 'midwest' else "alldata"
    cursor.execute("""
    WITH obs as (
        SELECT station, sday, day, precip from """ + table + """ WHERE
        day >= %s and day < %s and precip >= 0 and
        substr(station, 3, 1) != 'C' and substr(station, 3, 4) != '0000'),
    climo as (
        SELECT station, to_char(valid, 'mmdd') as sday, precip from
        climate51),
    combo as (
        SELECT o.station, o.precip - c.precip as d from obs o JOIN climo c ON
        (o.station = c.station and o.sday = c.sday)),
    deltas as (
        SELECT station, sum(d) from combo GROUP by station)

    SELECT d.station, d.sum, ST_x(t.geom), ST_y(t.geom) from deltas d
    JOIN stations t on (d.station = t.id) WHERE t.network ~* 'CLIMATE'
    """, (date1, date2))

    rows = []
    for row in cursor:
        rows.append(dict(station=row[0], delta=row[1], lon=row[2],
                         lat=row[3]))
    df = pd.DataFrame(rows)
    lons = np.array(df['lon'])
    vals = np.array(df['delta'])
    lats = np.array(df['lat'])
    sector2 = "state" if sector != 'midwest' else 'midwest'
    m = MapPlot(sector=sector2, state=sector, axisbg='white',
                title=('%s - %s Precipitation Departure [inch]'
                       ) % (date1.strftime("%d %b %Y"),
                            date2.strftime("%d %b %Y")),
                subtitle='%s vs 1950-2014 Climatology' % (date1.year,))
    rng = int(max([0 - np.min(vals), np.max(vals)]))
    cmap = cm.get_cmap('RdYlBu')
    cmap.set_bad('white')
    m.contourf(lons, lats, vals, np.linspace(0 - rng - 0.5, rng + 0.6, 10,
                                             dtype='i'),
               cmap=cmap, units='inch')
    m.plot_values(lons, lats, vals, fmt='%.2f')
    if sector == 'iowa':
        m.drawcounties()

    return m.fig, df
开发者ID:raprasad,项目名称:iem,代码行数:62,代码来源:p97.py

示例3: test_michigan

# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import contourf [as 别名]
def test_michigan():
    """See what we do with Michigan"""
    mp = MapPlot(sector='state', state='MI', nocaption=True)
    mp.contourf(np.arange(-84, -75), np.arange(36, 45), np.arange(9),
                np.arange(9),
                clevlabels=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
    return mp.fig
开发者ID:akrherz,项目名称:pyIEM,代码行数:9,代码来源:test_geoplot.py

示例4: test_contourf

# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import contourf [as 别名]
def test_contourf():
    ''' Test the contourf plot with labels specified '''
    mp = MapPlot(sector='iowa', nocaption=True)
    mp.contourf(np.arange(-94, -89), np.arange(40, 45),
                np.arange(5), np.arange(5),
                clevlabels=['a', 'b', 'c', 'd', 'e'])
    return mp.fig
开发者ID:akrherz,项目名称:pyIEM,代码行数:9,代码来源:test_geoplot.py

示例5: test_drawiowawfo

# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import contourf [as 别名]
def test_drawiowawfo():
    """Iowa Contour Plot"""
    mp = MapPlot(sector='iowawfo', title='Iowa Contour plot', nocaption=True)
    mp.contourf(np.arange(-94, -85), np.arange(36, 45), np.arange(9),
                np.arange(9),
                clevlabels=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
    return mp.fig
开发者ID:akrherz,项目名称:pyIEM,代码行数:9,代码来源:test_geoplot.py

示例6: run

# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import contourf [as 别名]
def run(year):
    cursor.execute("""
    WITH obs as (
    SELECT station, sum(precip) from alldata_ia where year = %s GROUP by station
    ), climate as (
    SELECT station, sum(precip) from climate51 GROUP by station
    )
    SELECT o.station, o.sum - c.sum as diff from obs o JOIN climate c 
    on (c.station = o.station) ORDER by diff ASC
    """, (year,))
    lats = []
    lons = []
    vals = []
    for row in cursor:
        if not nt.sts.has_key(row[0]) or row[0] in rejs or row[0][2] == 'C':
            continue
        print row
        lats.append( nt.sts[row[0]]['lat'])
        lons.append( nt.sts[row[0]]['lon'])
        vals.append( row[1] )
    
    m = MapPlot(title='%s Precipitation Departure' % (year,))
    cmap = cm.get_cmap('BrBG')
    #cmap.set_over('blue')
    #cmap.set_under('red')
    m.contourf(lons, lats, vals, np.arange(-24,24.1,2), cmap=cmap, units='inch')
    #m.plot_values(lons, lats, vals, '%.02f')
    m.drawcounties()
    m.postprocess(filename='%s.png' % (year,))
开发者ID:KayneWest,项目名称:iem,代码行数:31,代码来源:precip_departure.py

示例7: run

# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import contourf [as 别名]
def run(base, ceil, now, fn):
    """ Generate the plot """
    # Compute normal from the climate database
    sql = """SELECT station,
       sum(gddxx(%s, %s, high, low)) as gdd
       from alldata_ia WHERE year = %s and month in (5,6,7,8,9,10)
       and station != 'IA0000' and substr(station,2,1) != 'C'
       GROUP by station""" % (base, ceil, now.year)

    lats = []
    lons = []
    gdd50 = []
    ccursor.execute(sql)
    for row in ccursor:
        if row[0] not in nt.sts:
            continue
        lats.append(nt.sts[row[0]]['lat'])
        lons.append(nt.sts[row[0]]['lon'])
        gdd50.append(float(row[1]))

    m = MapPlot(title=("Iowa 1 May - %s GDD Accumulation"
                       ) % (now.strftime("%-d %B %Y"), ),
                subtitle="base %s" % (base,))
    bins = np.linspace(min(gdd50)-1, max(gdd50)+1, num=10, dtype=np.int)
    m.contourf(lons, lats, gdd50, bins)
    m.drawcounties()

    pqstr = "plot c 000000000000 summary/%s.png bogus png" % (fn,)
    m.postprocess(pqstr=pqstr)
开发者ID:KayneWest,项目名称:iem,代码行数:31,代码来源:plot_gdd.py

示例8: plotter

# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import contourf [as 别名]
def plotter(fdict):
    """ Go """
    import matplotlib
    matplotlib.use('agg')
    pgconn = psycopg2.connect(database='coop', host='iemdb', user='nobody')

    state = fdict.get('state', 'IA')[:2]
    varname = fdict.get('var', 'total_precip')
    sector = fdict.get('sector', 'state')
    opt = fdict.get('opt', 'both')
    over = fdict.get('over', 'monthly')
    month = int(fdict.get('month', datetime.date.today().month))

    df = read_sql("""
    WITH data as (
        SELECT station, extract(month from valid) as month,
        sum(precip) as total_precip, avg(high) as avg_high,
        avg(low) as avg_low, avg((high+low)/2.) as avg_temp
        from ncdc_climate81 GROUP by station, month)

    SELECT station, ST_X(geom) as lon, ST_Y(geom) as lat, month,
    total_precip, avg_high, avg_low, avg_temp from data d JOIN stations t
    ON (d.station = t.id) WHERE t.network = 'NCDC81' and
    t.state in ('IA', 'ND', 'SD', 'NE', 'KS', 'MO', 'IL', 'WI', 'MN', 'MI',
    'IN', 'OH', 'KY')
    """, pgconn, index_col=['station', 'month'])

    if over == 'monthly':
        title = "%s %s" % (calendar.month_name[month], PDICT3[varname])
        df.reset_index(inplace=True)
        df2 = df[df['month'] == month]
    else:
        title = "Annual %s" % (PDICT3[varname], )
        if varname == 'total_precip':
            df2 = df.sum(axis=0, level='station')
        else:
            df2 = df.mean(axis=0, level='station')
        df2['lat'] = df['lat'].mean(axis=0, level='station')
        df2['lon'] = df['lon'].mean(axis=0, level='station')
    m = MapPlot(sector=sector, state=state, axisbg='white',
                title=('NCEI 1981-2010 Climatology of %s'
                       ) % (title,),
                subtitle=('based on National Centers for '
                          'Environmental Information (NCEI) 1981-2010'
                          ' Climatology'))
    levels = np.linspace(df2[varname].min(), df2[varname].max(), 10)
    levels = [round(x, PRECISION[varname]) for x in levels]
    if opt in ['both', 'contour']:
        m.contourf(df2['lon'].values, df2['lat'].values,
                   df2[varname].values, levels, units=UNITS[varname])
    if sector == 'state':
        m.drawcounties()
    if opt in ['both', 'values']:
        m.plot_values(df2['lon'].values, df2['lat'].values,
                      df2[varname].values,
                      fmt='%%.%if' % (PRECISION[varname],))

    return m.fig, df
开发者ID:akrherz,项目名称:iem,代码行数:60,代码来源:p125.py

示例9: test_cwa

# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import contourf [as 别名]
def test_cwa():
    """Exercise the cwa plotting routines"""
    mp = MapPlot(sector='cwa', cwa='MKX', nocaption=True)
    mp.contourf(np.arange(-94, -89), np.arange(40, 45),
                np.arange(5), np.arange(5),
                clevlabels=['a', 'b', 'c', 'd', 'e'])
    mp.draw_cwas()
    assert mp.cwa == 'MKX'
    return mp.fig
开发者ID:akrherz,项目名称:pyIEM,代码行数:11,代码来源:test_geoplot.py

示例10: plotter

# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import contourf [as 别名]
def plotter(fdict):
    """ Go """
    import matplotlib
    matplotlib.use('agg')
    from pyiem.plot import MapPlot
    ptype = fdict.get('ptype', 'c')
    date = datetime.datetime.strptime(fdict.get('date', '2015-01-01'),
                                      '%Y-%m-%d')
    varname = fdict.get('var', 'rsds')

    idx0 = iemre.daily_offset(date)
    nc = netCDF4.Dataset(("/mesonet/data/iemre/%s_mw_daily.nc"
                          ) % (date.year, ), 'r')
    lats = nc.variables['lat'][:]
    lons = nc.variables['lon'][:]
    if varname == 'rsds':
        # Value is in W m**-2, we want MJ
        data = nc.variables[varname][idx0, :, :] * 86400. / 1000000.
        units = 'MJ d-1'
        clevs = np.arange(0, 37, 3.)
        clevs[0] = 0.01
        clevstride = 1
    elif varname in ['p01d', 'p01d_12z']:
        # Value is in W m**-2, we want MJ
        data = nc.variables[varname][idx0, :, :] / 25.4
        units = 'inch'
        clevs = np.arange(0, 0.25, 0.05)
        clevs = np.append(clevs, np.arange(0.25, 3., 0.25))
        clevs = np.append(clevs, np.arange(3., 10.0, 1))
        clevs[0] = 0.01
        clevstride = 1
    elif varname in ['high_tmpk', 'low_tmpk', 'high_tmpk_12z', 'low_tmpk_12z']:
        # Value is in W m**-2, we want MJ
        data = temperature(nc.variables[varname][idx0, :, :], 'K').value('F')
        units = 'F'
        clevs = np.arange(-30, 120, 2)
        clevstride = 5
    nc.close()

    title = date.strftime("%-d %B %Y")
    m = MapPlot(sector='midwest', axisbg='white', nocaption=True,
                title='IEM Reanalysis of %s for %s' % (PDICT.get(varname),
                                                       title),
                subtitle='Data derived from various NOAA datasets'
                )
    if np.ma.is_masked(np.max(data)):
        return 'Data Unavailable'
    x, y = np.meshgrid(lons, lats)
    if ptype == 'c':
        m.contourf(x, y, data, clevs, clevstride=clevstride, units=units)
    else:
        m.pcolormesh(x, y, data, clevs, clevstride=clevstride, units=units)

    return m.fig
开发者ID:raprasad,项目名称:iem,代码行数:56,代码来源:p86.py

示例11: doit

# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import contourf [as 别名]
def doit(now):
    """
      Generate some plots for the COOP data!
    """
    # We'll assume all COOP data is 12z, sigh for now
    sql = """SELECT id, pday, network
           from summary_%s s JOIN stations t ON (t.iemid = s.iemid) 
           WHERE day = '%s' and
           t.network ~* 'COOP' and pday >= 0""" % (now.year,
           now.strftime("%Y-%m-%d") )

    lats = []
    lons = []
    vals = []
    icursor.execute( sql )
    iamax = 0.
    for row in icursor:
        sid = row[0]
        if not st.sts.has_key(sid):
            continue
        #labels.append( id[2:] )
        lats.append( st.sts[sid]['lat'] )
        lons.append( st.sts[sid]['lon'] )
        vals.append( row[1] )
        if row[2] == 'IA_COOP' and row[1] > iamax:
            iamax = row[1]

#if iamax == 0:
# Dummy in some bad data to prevent the contouring from going mad
#      lats.append( 42. )
#      lons.append( -96.0 )
#      vals.append( 1. )
    
    # Plot Iowa
    m = MapPlot(sector='iowa',
                title='24 Hour NWS COOP Precipitation [inch]',
                subtitle='Ending %s at roughly 12Z' % (now.strftime("%d %B %Y"),))

    m.contourf(lons, lats, vals, clevs, units='inch')

    pqstr = "plot ac %s0000 iowa_coop_12z_precip.png iowa_coop_12z_precip.png png" % (now.strftime("%Y%m%d"),)
    m.postprocess(pqstr=pqstr)
    m.close()

    m = MapPlot(sector='midwest',
                title='24 Hour NWS COOP Precipitation [inch]',
                subtitle='Ending %s at roughly 12Z' % (now.strftime("%d %B %Y"),))

    m.contourf(lons, lats, vals, clevs, units='inch')

    pqstr = "plot ac %s0000 midwest_coop_12z_precip.png midwest_coop_12z_precip.png png" % (now.strftime("%Y%m%d"),)
    m.postprocess(pqstr=pqstr)
    m.close()
开发者ID:KayneWest,项目名称:iem,代码行数:55,代码来源:12z_precip.py

示例12: plotter

# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import contourf [as 别名]
def plotter(fdict):
    """ Go """
    pgconn = psycopg2.connect(database='coop', host='iemdb', user='nobody')
    cursor = pgconn.cursor(cursor_factory=psycopg2.extras.DictCursor)

    date1 = datetime.datetime.strptime(fdict.get('date1', '2014-09-01'),
                                       '%Y-%m-%d')
    date2 = datetime.datetime.strptime(fdict.get('date2', '2014-09-22'),
                                       '%Y-%m-%d')
    date1 = date1.replace(year=2000)
    date2 = date2.replace(year=2000)

    varname = fdict.get('varname', 'low')

    cursor.execute("""
    WITH t2 as (
         SELECT station, high, low from ncdc_climate81 WHERE
         valid = %s
    ), t1 as (
        SELECT station, high, low from ncdc_climate81 where
        valid = %s
    ), data as (
        SELECT t2.station, t1.high as t1_high, t2.high as t2_high,
        t1.low as t1_low, t2.low as t2_low from t1 JOIN t2 on
        (t1.station = t2.station)
    )
    SELECT d.station, ST_x(geom) as lon, ST_y(geom) as lat,
    t2_high -  t1_high as high, t2_low - t1_low as low from data d JOIN
    stations s on (s.id = d.station) where s.network = 'NCDC81'
    """, (date2, date1))
    vals = []
    lons = []
    lats = []
    for row in cursor:
        lats.append(row['lat'])
        lons.append(row['lon'])
        vals.append(row[varname])

    days = int((date2 - date1).days)
    extent = int(max(abs(min(vals)), abs(max(vals))))
    m = MapPlot(sector='conus',
                title=('%s Day Change in %s NCDC 81 Climatology'
                       ) % (days, PDICT[varname]),
                subtitle='from %s to %s' % (date1.strftime("%-d %B"),
                                            date2.strftime("%-d %B"))
                )
    cmap = cm.get_cmap("RdBu_r")
    m.contourf(lons, lats, vals, np.arange(0-extent, extent+1, 2), cmap=cmap,
               units='F')

    return m.fig
开发者ID:KayneWest,项目名称:iem,代码行数:53,代码来源:p21.py

示例13: plotter

# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import contourf [as 别名]
def plotter(fdict):
    """ Go """
    import matplotlib
    matplotlib.use('agg')
    from pyiem.plot import MapPlot
    import matplotlib.cm as cm
    pgconn = psycopg2.connect(database='coop', host='iemdb', user='nobody')

    date1 = datetime.datetime.strptime(fdict.get('date1', '2014-09-01'),
                                       '%Y-%m-%d')
    date2 = datetime.datetime.strptime(fdict.get('date2', '2014-09-22'),
                                       '%Y-%m-%d')
    date1 = date1.replace(year=2000)
    date2 = date2.replace(year=2000)

    varname = fdict.get('varname', 'low')

    df = read_sql("""
    WITH t2 as (
         SELECT station, high, low from ncdc_climate81 WHERE
         valid = %s
    ), t1 as (
        SELECT station, high, low from ncdc_climate81 where
        valid = %s
    ), data as (
        SELECT t2.station, t1.high as t1_high, t2.high as t2_high,
        t1.low as t1_low, t2.low as t2_low from t1 JOIN t2 on
        (t1.station = t2.station)
    )
    SELECT d.station, ST_x(geom) as lon, ST_y(geom) as lat,
    t2_high -  t1_high as high, t2_low - t1_low as low from data d JOIN
    stations s on (s.id = d.station) where s.network = 'NCDC81'
    and s.state not in ('HI', 'AK')
    """, pgconn, params=(date2, date1), index_col='station')

    days = int((date2 - date1).days)
    extent = int(df[varname].abs().max())
    m = MapPlot(sector='conus',
                title=('%s Day Change in %s NCDC 81 Climatology'
                       ) % (days, PDICT[varname]),
                subtitle='from %s to %s' % (date1.strftime("%-d %B"),
                                            date2.strftime("%-d %B"))
                )
    cmap = cm.get_cmap("RdBu_r")
    m.contourf(df['lon'].values, df['lat'].values, df[varname].values,
               np.arange(0-extent, extent+1, 2), cmap=cmap, units='F')

    return m.fig, df
开发者ID:muthulatha,项目名称:iem,代码行数:50,代码来源:p21.py

示例14: plotter

# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import contourf [as 别名]
def plotter(fdict):
    """ Go """
    import matplotlib
    matplotlib.use('agg')
    from pyiem.plot import MapPlot
    pgconn = psycopg2.connect(dbname='coop', host='iemdb', user='nobody')
    ctx = util.get_autoplot_context(fdict, get_description())
    sector = ctx['sector']
    varname = ctx['var']
    year = ctx['year']
    popt = ctx['popt']
    threshold = ctx['threshold']
    table = "alldata_%s" % (sector,)
    df = read_sql("""
    WITH data as (
        SELECT station, """ + SQLOPT[varname] + """ as doy
        from """ + table + """
        WHERE year = %s GROUP by station
    )
    select station, doy, st_x(geom) as lon, st_y(geom) as lat
    from data d JOIN stations t on (d.station = t.id) WHERE
    t.network = %s and substr(station, 3, 4) != '0000'
    and substr(station, 3, 1) != 'C' and doy not in (0, 400) ORDER by doy
    """, pgconn, params=(threshold, year, '%sCLIMATE' % (sector,)),
                  index_col='station')
    if len(df.index) == 0:
        return "No data found!"

    def f(val):
        ts = datetime.date(year, 1, 1) + datetime.timedelta(days=(val - 1))
        return ts.strftime("%-m/%-d")

    df['pdate'] = df['doy'].apply(f)

    m = MapPlot(sector='state', state=sector, axisbg='white', nocaption=True,
                title="%s %s %s$^\circ$F" % (year, PDICT2[varname], threshold),
                subtitle='based on NWS COOP and IEM Daily Estimates')
    levs = np.linspace(df['doy'].min() - 3, df['doy'].max() + 3, 7, dtype='i')
    levlables = map(f, levs)
    if popt == 'contour':
        m.contourf(df['lon'], df['lat'], df['doy'], levs, clevlabels=levlables)
    m.plot_values(df['lon'], df['lat'], df['pdate'], labelbuffer=5)
    m.drawcounties()

    return m.fig, df
开发者ID:akrherz,项目名称:iem,代码行数:47,代码来源:p165.py

示例15: plotter

# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import contourf [as 别名]
def plotter(fdict):
    """ Go """
    import matplotlib
    matplotlib.use('agg')
    from pyiem.plot import MapPlot
    ptype = fdict.get('ptype', 'c')
    date = datetime.datetime.strptime(fdict.get('date', '2015-01-01'),
                                      '%Y-%m-%d')
    varname = fdict.get('var', 'rsds')

    idx0 = iemre.daily_offset(date)
    nc = netCDF4.Dataset(("/mesonet/data/iemre/%s_mw_daily.nc"
                          ) % (date.year, ), 'r')
    lats = nc.variables['lat'][:]
    lons = nc.variables['lon'][:]
    if varname == 'rsds':
        # Value is in W m**-2, we want MJ
        data = nc.variables['rsds'][idx0, :, :] * 86400. / 1000000.
        units = 'MJ d-1'
    nc.close()

    title = date.strftime("%-d %B %Y")
    m = MapPlot(sector='midwest', axisbg='white', nocaption=True,
                title='IEM Reanalysis of %s for %s' % (PDICT.get(varname),
                                                       title),
                subtitle='Data derived from various NOAA datasets'
                )
    if np.ma.is_masked(np.max(data)):
        return 'Data Unavailable'
    clevs = np.arange(0, 37, 3.)
    clevs[0] = 0.01
    x, y = np.meshgrid(lons, lats)
    if ptype == 'c':
        m.contourf(x, y, data, clevs, units=units)
    else:
        m.pcolormesh(x, y, data, clevs, units=units)

    return m.fig
开发者ID:danhreitz,项目名称:iem,代码行数:40,代码来源:p86.py


注:本文中的pyiem.plot.MapPlot.contourf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。