本文整理汇总了Python中pyiem.plot.MapPlot.fill_climdiv方法的典型用法代码示例。如果您正苦于以下问题:Python MapPlot.fill_climdiv方法的具体用法?Python MapPlot.fill_climdiv怎么用?Python MapPlot.fill_climdiv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyiem.plot.MapPlot
的用法示例。
在下文中一共展示了MapPlot.fill_climdiv方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plotter
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_climdiv [as 别名]
def plotter(fdict):
""" Go """
import matplotlib
matplotlib.use('agg')
from pyiem.plot import MapPlot
pgconn = psycopg2.connect(database='coop', host='iemdb', user='nobody')
year = int(fdict.get('year', 2014))
month = int(fdict.get('month', 9))
varname = fdict.get('var', 'precip')
lastyear = datetime.date.today().year
years = lastyear - 1893 + 1
df = read_sql("""
with monthly as (
SELECT year, station,
sum(precip) as p,
avg((high+low)/2.) as avgt
from alldata
WHERE substr(station,3,1) = 'C' and month = %s
GROUP by year, station),
ranks as (
SELECT station, year,
rank() OVER (PARTITION by station ORDER by p DESC) as precip_rank,
rank() OVER (PARTITION by station ORDER by avgt DESC) as avgt_rank
from monthly)
SELECT station, precip_rank, avgt_rank from ranks
where year = %s """, pgconn, params=(month, year), index_col='station')
m = MapPlot(sector='midwest', axisbg='white',
title='%s %s %s Ranks by Climate District' % (
year, calendar.month_name[month], PDICT[varname]),
subtitle=('Based on IEM Estimates, '
'1 is %s out of %s total years (1893-%s)'
) % ('wettest' if varname == 'precip' else 'hottest',
years, lastyear)
)
cmap = cm.get_cmap("BrBG_r" if varname == 'precip' else 'BrBG')
cmap.set_under('white')
cmap.set_over('black')
m.fill_climdiv(df[varname+'_rank'], ilabel=True, plotmissing=False,
bins=[1, 5, 10, 25, 50, 75, 100, years-10, years-5, years],
cmap=cmap)
return m.fig, df
示例2: plotter
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_climdiv [as 别名]
def plotter(fdict):
""" Go """
import matplotlib
matplotlib.use('agg')
from pyiem.plot import MapPlot
pgconn = psycopg2.connect(database='coop', host='iemdb', user='nobody')
cursor = pgconn.cursor(cursor_factory=psycopg2.extras.DictCursor)
year = int(fdict.get('year', 2014))
month = int(fdict.get('month', 9))
lastyear = datetime.date.today().year
years = lastyear - 1893 + 1
cursor.execute("""
with monthly as (
SELECT year, station, sum(precip) as p from alldata
WHERE substr(station,3,1) = 'C' and month = %s
GROUP by year, station),
ranks as (
SELECT station, year,
rank() OVER (PARTITION by station ORDER by p DESC) from monthly)
SELECT station, rank from ranks where year = %s """, (month, year))
data = {}
rows = []
for row in cursor:
data[row['station']] = row['rank']
rows.append(dict(station=row['station'], rank=row['rank']))
df = pd.DataFrame(rows)
m = MapPlot(sector='midwest', axisbg='white',
title='%s %s Precipitation Total Ranks by Climate District' % (
year, calendar.month_name[month]),
subtitle=('Based on IEM Estimates, '
'1 is wettest out of %s total years (1893-%s)'
) % (years, lastyear)
)
cmap = cm.get_cmap("BrBG_r")
cmap.set_under('white')
cmap.set_over('black')
m.fill_climdiv(data,
bins=[1, 5, 10, 25, 50, 75, 100, years-10, years-5, years],
cmap=cmap)
return m.fig, df
示例3: avg
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_climdiv [as 别名]
from pyiem.plot import MapPlot
import numpy
import psycopg2
dbconn = psycopg2.connect(database='coop', host='iemdb', user='nobody')
cursor = dbconn.cursor()
clim = {}
cursor.execute("""SELECT station, avg(sum) from
(SELECT station, year, sum(precip) from alldata where
year < 2013 and year > 1950 and substr(station,3,1) = 'C' and month in (4,5)
and sday < '0520' GROUP by station, year) as foo
GROUP by station""")
for row in cursor:
clim[ row[0] ] = row[1]
data = {}
cursor.execute("""SELECT station, sum(precip) from alldata where
year = 2013 and substr(station,3,1) = 'C' and month in (4,5) GROUP by station""")
for row in cursor:
data[ row[0] ] = row[1] - clim[ row[0] ]
m = MapPlot(sector='midwest', title='IEM Estimated Climate Division Precipitation Departure [inch]', subtitle='1 April thru 19 May 2013 vs 1950-2012 Climate')
m.fill_climdiv(data, bins=numpy.arange(5,-5.1,-0.25), lblformat='%.1f')
m.postprocess(filename='test.svg')
import iemplot
iemplot.makefeature('test')
示例4: plotter
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_climdiv [as 别名]
def plotter(fdict):
""" Go """
import matplotlib
matplotlib.use('agg')
from pyiem.plot import MapPlot
pgconn = psycopg2.connect(database='coop', host='iemdb', user='nobody')
year = int(fdict.get('year', 2014))
month = fdict.get('month', 9)
varname = fdict.get('var', 'precip')
l = "0 days"
if month == 'fall':
months = [9, 10, 11]
label = "Fall (SON)"
elif month == 'winter':
months = [12, 1, 2]
l = "32 days"
label = "Winter (DJF)"
elif month == 'spring':
months = [3, 4, 5]
label = "Spring (MAM)"
elif month == 'summer':
months = [6, 7, 8]
label = "Summer (JJA)"
else:
months = [int(month), ]
label = calendar.month_name[int(month)]
lastyear = datetime.date.today().year
years = lastyear - 1893 + 1
df = read_sql("""
with monthly as (
SELECT extract(year from day + '"""+l+"""'::interval) as myyear,
station, sum(precip) as p,
avg((high+low)/2.) as avgt,
avg(high) as avghi
from alldata
WHERE substr(station,3,1) = 'C' and month in %s
GROUP by myyear, station),
ranks as (
SELECT station, myyear as year,
avg(p) OVER (PARTITION by station) as avg_precip,
stddev(p) OVER (PARTITION by station) as std_precip,
p as precip,
avg(avghi) OVER (PARTITION by station) as avg_high,
stddev(avghi) OVER (PARTITION by station) as std_high,
avghi as high,
rank() OVER (PARTITION by station ORDER by p DESC) as precip_rank,
rank() OVER (PARTITION by station ORDER by avgt DESC) as avgt_rank
from monthly)
SELECT station, precip_rank, avgt_rank,
((high - avg_high) / std_high) - ((precip - avg_precip) / std_precip)
as arridity from ranks
where year = %s """, pgconn, params=(tuple(months), year),
index_col='station')
subtitle = ('Based on IEM Estimates, '
'1 is %s out of %s total years (1893-%s)'
) % ('wettest' if varname == 'precip' else 'hottest',
years, lastyear)
if varname == 'arridity':
subtitle = "Std Average High Temp Departure minus Std Precip Departure"
m = MapPlot(sector='midwest', axisbg='white',
title='%s %s %s %sby Climate District' % (
year, label, PDICT[varname],
'Ranks ' if varname != 'arridity' else ''),
subtitle=subtitle)
cmap = cm.get_cmap("BrBG_r" if varname in ['precip', 'arridity']
else 'BrBG')
cmap.set_under('white')
cmap.set_over('black')
bins = [1, 5, 10, 25, 50, 75, 100, years-10, years-5, years]
pvar = varname+'_rank'
fmt = '%.0f'
if varname == 'arridity':
bins = np.arange(-4, 4.1, 1)
pvar = varname
fmt = '%.1f'
m.fill_climdiv(df[pvar], ilabel=True, plotmissing=False, lblformat=fmt,
bins=bins,
cmap=cmap)
return m.fig, df
示例5: as
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_climdiv [as 别名]
import matplotlib.cm as cm
pgconn = psycopg2.connect(database='coop', host='iemdb', user='nobody')
cursor = pgconn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cursor.execute("""
with monthly as (
SELECT station, extract(year from day + '40 days'::interval) as yr,
avg((high+low)/2.) from alldata
where month in (12,1,2) and substr(station,3,1) = 'C' GROUP by station, yr
),
nextup as (
SELECT station, yr, rank() OVER (PARTITION by station ORDER by avg ASC)
from monthly
)
SELECT station, rank from nextup where yr = 2015
""")
data = {}
for row in cursor:
data[row['station']] = row['rank']
m = MapPlot(sector='midwest', axisbg='white',
title='Dec 2014 - Jan/Feb 2015 Average Temperature Rank (1 is coldest)',
subtitle='Based on IEM Estimates of Climate District Data (1893-2015)')
cmap = cm.get_cmap("BrBG_r")
cmap.set_under('black')
cmap.set_over('black')
m.fill_climdiv(data, cmap=cmap, bins=[1, 10, 25, 50, 75, 100, 115, 123])
m.postprocess(filename='test.png')
示例6: test_plot3
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_climdiv [as 别名]
def test_plot3():
""" Exercise climdiv plot API """
mp = MapPlot(sector='iowa', nocaption=True)
mp.fill_climdiv({'IAC001': 80, 'AKC003': 5, 'HIC003': 30,
'AJK': 40, 'HFO': 50})
return mp.fig
示例7: test_climdiv
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_climdiv [as 别名]
def test_climdiv():
"""Run tests agains the fill_climdiv"""
mp = MapPlot(sector='conus', title="Climate Divisions", nocaption=True)
data = {'IAC001': 10, 'MNC001': 20, 'NMC001': 30}
mp.fill_climdiv(data, ilabel=True)
return mp.fig