本文整理汇总了Python中pyiem.plot.MapPlot.plot_values方法的典型用法代码示例。如果您正苦于以下问题:Python MapPlot.plot_values方法的具体用法?Python MapPlot.plot_values怎么用?Python MapPlot.plot_values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyiem.plot.MapPlot
的用法示例。
在下文中一共展示了MapPlot.plot_values方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_month
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import plot_values [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)
示例2: runYear
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import plot_values [as 别名]
def runYear(year):
# Grab the data
sql = """SELECT station, sum(precip) as total, max(day)
from alldata_ia WHERE year = %s and
station != 'IA0000' and
substr(station,3,1) != 'C' and
precip is not null GROUP by station""" % (year,)
lats = []
lons = []
vals = []
labels = []
ccursor.execute( sql )
for row in ccursor:
sid = row['station']
if not nt.sts.has_key(sid):
continue
labels.append( sid[2:] )
lats.append( nt.sts[sid]['lat'] )
lons.append( nt.sts[sid]['lon'] )
vals.append( row['total'] )
maxday = row['max']
m = MapPlot(title="Total Precipitation [inch] (%s)" % (year,),
subtitle='1 January - %s' % (maxday.strftime("%d %B"),),
axisbg='white')
m.plot_values(lons, lats, vals, labels=labels, fmt='%.2f',
labeltextsize=8, labelcolor='tan')
pqstr = "plot m %s bogus %s/summary/total_precip.png png" % (
now.strftime("%Y%m%d%H%M"), year,)
m.postprocess(pqstr=pqstr)
示例3: main
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import plot_values [as 别名]
def main():
"""Map some CLI data"""
pgconn = get_dbconn('iem')
df = read_sql("""
WITH data as (
SELECT station, snow_jul1 - snow_jul1_normal as s
from cli_data where valid = '2019-02-18' and snow_jul1 > 0
and snow_jul1_normal > 0)
select station, st_x(geom) as lon, st_y(geom) as lat, c.s as val from
data c JOIN stations s on (s.id = c.station)
WHERE s.network = 'NWSCLI'
""", pgconn, index_col=None)
df['color'] = '#ff0000'
df.loc[df['val'] > 0, 'color'] = '#0000ff'
mp = MapPlot(sector='midwest', axisbg='white',
title=("2018-2019 Snowfall Total Departure "
"from Average [inches]"),
subtitle='18 Feb 2019 Based on NWS CLI Reporting Sites')
mp.plot_values(
df['lon'].values, df['lat'].values,
df['val'].values, fmt='%.1f', textsize=12, color=df['color'].values,
labelbuffer=1)
mp.postprocess(filename='test.png')
示例4: runYear
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import plot_values [as 别名]
def runYear(year):
# Grab the data
sql = """SELECT station,
sum(case when precip >= 0.01 then 1 else 0 end) as days, max(day)
from alldata_ia WHERE year = %s and substr(station,3,1) != 'C'
and station != 'IA0000' GROUP by station""" % (year,)
lats = []
lons = []
vals = []
labels = []
ccursor.execute( sql )
for row in ccursor:
sid = row['station'].upper()
if not nt.sts.has_key(sid):
continue
labels.append( sid[2:] )
lats.append( nt.sts[sid]['lat'] )
lons.append( nt.sts[sid]['lon'] )
vals.append( row['days'] )
maxday = row['max']
#---------- Plot the points
m = MapPlot(title="Days with Measurable Precipitation (%s)" % (year,),
subtitle='Map valid January 1 - %s' % (maxday.strftime("%b %d")),
axisbg='white')
m.plot_values(lons, lats, vals, fmt='%.0f', labels=labels,
labeltextsize=8, labelcolor='tan')
m.drawcounties()
pqstr = "plot m %s bogus %s/summary/precip_days.png png" % (
now.strftime("%Y%m%d%H%M"), year,)
m.postprocess(pqstr=pqstr)
示例5: doday
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import plot_values [as 别名]
def doday():
"""
Create a plot of precipitation stage4 estimates for some day
"""
sts = mx.DateTime.DateTime(2013,5,25,12)
ets = mx.DateTime.DateTime(2013,5,31,12)
interval = mx.DateTime.RelativeDateTime(days=1)
now = sts
total = None
while now < ets:
fp = "/mesonet/ARCHIVE/data/%s/stage4/ST4.%s.24h.grib" % (
now.strftime("%Y/%m/%d"),
now.strftime("%Y%m%d%H") )
if os.path.isfile(fp):
lts = now
grbs = pygrib.open(fp)
if total is None:
g = grbs[1]
total = g["values"]
lats, lons = g.latlons()
else:
total += grbs[1]["values"]
grbs.close()
now += interval
m = MapPlot(sector='iowa', title='NOAA Stage IV & Iowa ASOS Precipitation',
subtitle='25-30 May 2013')
m.pcolormesh(lons, lats, total / 25.4, numpy.arange(0,14.1,1), latlon=True,
units='inch')
m.drawcounties()
m.plot_values(dlons, dlats, dvals, '%.02f')
m.postprocess(filename='test.svg')
import iemplot
iemplot.makefeature('test')
示例6: plot
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import plot_values [as 别名]
def plot(data, v):
''' Actually plot this data '''
nt = NetworkTable("ISUSM")
lats = []
lons = []
vals = []
valid = None
for sid in data.keys():
if data[sid][v] is None:
continue
lats.append(nt.sts[sid]['lat'])
lons.append(nt.sts[sid]['lon'])
vals.append(data[sid][v])
valid = data[sid]['valid']
if valid is None:
m = MapPlot(sector='iowa', axisbg='white',
title=('ISU Soil Moisture Network :: %s'
'') % (CTX[v]['title'], ),
figsize=(8.0, 6.4))
m.plot_values([-95, ], [41.99, ], ['No Data Found'], '%s', textsize=30)
m.postprocess(web=True)
return
m = MapPlot(sector='iowa', axisbg='white',
title='ISU Soil Moisture Network :: %s' % (CTX[v]['title'],),
subtitle='valid %s' % (valid.strftime("%-d %B %Y %I:%M %p"),),
figsize=(8.0, 6.4))
m.plot_values(lons, lats, vals, '%.1f')
m.drawcounties()
m.postprocess(web=True)
示例7: plotter
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import plot_values [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
示例8: main
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import plot_values [as 别名]
def main():
"""Go!"""
title = 'NOAA MRMS Q3: RADAR + Guage Corrected Rainfall Estimates + NWS Storm Reports'
mp = MapPlot(sector='custom',
north=42.3, east=-93.0, south=41.65, west=-94.1,
axisbg='white',
titlefontsize=14,
title=title,
subtitle='Valid: 14 June 2018')
shp = shapefile.Reader('cities.shp')
for record in shp.shapeRecords():
geo = shape(record.shape)
mp.ax.add_geometries([geo], ccrs.PlateCarree(), zorder=Z_OVERLAY2,
facecolor='None', edgecolor='k', lw=2)
grbs = pygrib.open('MRMS_GaugeCorr_QPE_24H_00.00_20180614-200000.grib2')
grb = grbs.message(1)
pcpn = distance(grb['values'], 'MM').value('IN')
lats, lons = grb.latlons()
lons -= 360.
clevs = [0.01, 0.1, 0.3, 0.5, 0.75, 1, 1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 8, 10]
cmap = nwsprecip()
cmap.set_over('k')
mp.pcolormesh(lons, lats, pcpn, clevs, cmap=cmap, latlon=True,
units='inch')
lons, lats, vals, labels = get_data()
mp.drawcounties()
mp.plot_values(lons, lats, vals, "%s", labels=labels,
labelbuffer=1, labelcolor='white')
mp.drawcities(labelbuffer=5, minarea=0.2)
mp.postprocess(filename='test.png')
示例9: plotter
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import plot_values [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
示例10: test_overlap
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import plot_values [as 别名]
def test_overlap():
""" Do some checking of our overlaps logic """
mp = MapPlot(sector='midwest', continentalcolor='white', nocaption=True)
lons = np.linspace(-99, -90, 100)
lats = np.linspace(38, 44, 100)
vals = lats
labels = ['%.2f' % (s,) for s in lats]
mp.plot_values(lons, lats, vals, fmt='%.2f', labels=labels)
return mp.fig
示例11: test_drawrandomtext
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import plot_values [as 别名]
def test_drawrandomtext():
"""See if we can handle the fun that is drawing random text"""
mp = MapPlot(sector='iowa', title='Fun Text, here and there',
continentalcolor='white', debug=True, nocaption=True)
mp.plot_values([-94, -92, -91, -92],
[42, 41, 43, 42.4],
['One', 'Two\nTwo', 'Three\nThree\nThree',
'Four\nFour\nFour\nFour'], showmarker=True)
return mp.fig
示例12: plot_precip_month
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import plot_values [as 别名]
def plot_precip_month(valid):
""" Go Main Go
Args:
valid (datetime): The timestamp we are interested in!
"""
pgconn = psycopg2.connect(database='iem', host='iemdb', user='nobody')
cursor = pgconn.cursor()
d1 = valid.replace(day=1)
d2 = d1 + datetime.timedelta(days=35)
d2 = d2.replace(day=1)
cursor.execute("""SELECT sum(pday), id, st_x(geom), st_y(geom)
from summary s JOIN stations t on
(t.iemid = s.iemid) WHERE s.day >= %s and s.day < %s
and t.network in ('IA_COOP', 'NE_COOP', 'MO_COOP', 'IL_COOP', 'WI_COOP',
'MN_COOP')
and pday is not null and pday >= 0 and
extract(hour from coop_valid) between 5 and 10
GROUP by id, st_x, st_y""", (d1.date(), d2.date()))
labels = []
vals = []
lats = []
lons = []
for row in cursor:
labels.append(row[1])
vals.append(pretty(row[0]))
lats.append(row[3])
lons.append(row[2])
m = MapPlot(title='%s NWS COOP Month Precipitation Totals [inch]' % (
valid.strftime("%-d %b %Y"),),
subtitle='Reports valid between 6 and 9 AM',
axisbg='white', figsize=(10.24, 7.68))
m.plot_values(lons, lats, vals, fmt='%s', labels=labels,
labelcolor='tan')
m.drawcounties()
pqstr = "plot ac %s0000 coopMonthPlot.gif coopMonthPlot.gif gif" % (
valid.strftime("%Y%m%d"),)
m.postprocess(pqstr=pqstr)
m.close()
pgconn.close()
示例13: plotter
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import plot_values [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
示例14: test_issue98_labelbar
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import plot_values [as 别名]
def test_issue98_labelbar():
"""Sometimes our label bar sucks."""
mp = MapPlot(
title='Proportional Colorbar with some rotation',
sector='iowa', nocaption=True)
cmap = plot.maue()
cmap.set_under('white')
cmap.set_over('black')
clevs = np.arange(0, 1., 0.1)
clevs[-1] = 3.987654
norm = mpcolors.BoundaryNorm(clevs, cmap.N)
mp.plot_values(
[-94, -92, -91, -92], [42, 41, 43, 42.4],
['0.5', '0.25', '1.0', '5.0'], color=cmap(norm([0.5, 0.25, 1.0, 5.0])),
showmarker=True
)
mp.draw_colorbar(clevs, cmap, norm, spacing='proportional')
return mp.fig
示例15: main
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import plot_values [as 别名]
def main():
"""Go Main!"""
nt = NetworkTable("IACLIMATE")
pgconn = get_dbconn('coop')
df = read_sql("""
with monthly as (
select station, year, month, avg((high+low)/2.) from alldata_ia
WHERE day < '2018-06-01' and high is not null
GROUP by station, year, month),
agg as (
select station, year, month, avg,
lag(avg) OVER (PARTITION by station ORDER by year ASC, month ASC)
from monthly),
agg2 as (
select station, year, month, avg, lag, avg - lag as val,
rank() OVER (PARTITION by station ORDER by avg - lag DESC)
from agg WHERE lag is not null)
select * from agg2 where rank = 1 ORDER by station
""", pgconn, index_col='station')
df['lat'] = 0.
df['lon'] = 0.
for station, _ in df.iterrows():
if station in nt.sts and station != 'IA0000' and station[2] != 'C':
df.at[station, 'lat'] = nt.sts[station]['lat']
df.at[station, 'lon'] = nt.sts[station]['lon']
mp = MapPlot(title="Largest Positive Change in Month to Month Average Temperature",
subtitle=('values in red set record for April to May 2018'), sector='state',
state='IA',
drawstates=True, continentalcolor='white')
df2 = df[df['year'] == 2018]
mp.plot_values(df2['lon'].values,
df2['lat'].values,
df2['val'].values, fmt='%.1f', textsize=12, labelbuffer=5,
color='r')
df2 = df[df['year'] != 2018]
mp.plot_values(df2['lon'].values,
df2['lat'].values,
df2['val'].values, fmt='%.1f', textsize=12, labelbuffer=5,
color='b')
mp.drawcounties()
mp.postprocess(filename='test.png')
mp.close()