本文整理汇总了Python中vcs.getcolors函数的典型用法代码示例。如果您正苦于以下问题:Python getcolors函数的具体用法?Python getcolors怎么用?Python getcolors使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getcolors函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: initVCS
def initVCS(x,levs1,levs2,split):
x.setcolormap("bl_to_darkred")
iso1 = x.createisofill()
#iso = x.createboxfill()
#iso.boxfill_type="custom"
iso1.levels = levs1
iso1.ext_1 = True
iso1.ext_2 = True
cols = vcs.getcolors(iso1.levels,split=split)
iso1.fillareacolors = cols
iso2 = x.createisofill()
levs = levs2
iso2.levels = levs
iso2.ext_1 = True
iso2.ext_2 = True
cols = vcs.getcolors(iso2.levels,split=1)
iso2.fillareacolors = cols
leg = x.createtextorientation()
leg.halign = "left"
leg.height = 8
tmpl = x.createtemplate()
tmpl.blank()
tmpl.scalefont(.9)
oldOrientation = tmpl.legend.textorientation
tmpl.legend.textorientation = leg
for a in ["data","legend","box1","xlabel1","xtic1","ylabel1","ytic1"]:
setattr(getattr(tmpl,a),"priority",1)
Ez = EzTemplate.Multi(rows=3,columns=1,x=x,template=tmpl)
Ez.legend.direction ='vertical'
Ez.margins.left =.05
Ez.margins.right =.05
Ez.margins.top =.05
Ez.margins.bottom =.05
title = x.createtext()
title.height = 14
title.halign = "center"
title.x = [.5]
title.y = [.975]
t1 = Ez.get(legend="local")
t2 = Ez.get(legend="local")
t3 = Ez.get(legend="local")
del(Ez) ; # Purge EzTemplate object
vcs.removeobject(vcs.elements['textorientation'][oldOrientation])
return iso1,iso2,title,t1,t2,t3,tmpl
开发者ID:PCMDI,项目名称:amipbcs,代码行数:53,代码来源:make_newVsOldDiffs.py
示例2: _updateContourLevelsAndColorsForCustomBoxfill
def _updateContourLevelsAndColorsForCustomBoxfill(self):
"""Set contour information for a custom boxfill."""
self._contourLevels = self._gm.levels
if numpy.allclose(self._contourLevels[0], [0., 1.e20]) or \
numpy.allclose(self._contourLevels, 1.e20):
levs2 = vcs.mkscale(self._scalarRange[0],
self._scalarRange[1])
if len(levs2) == 1: # constant value ?
levs2 = [levs2[0], levs2[0] + .00001]
self._contourLevels = []
if self._gm.ext_1:
## user wants arrow at the end
levs2[0] = -1.e20
if self._gm.ext_2:
## user wants arrow at the end
levs2[-1] = 1.e20
for i in range(len(levs2) - 1):
self._contourLevels.append([levs2[i], levs2[i+1]])
else:
if not isinstance(self._gm.levels[0], (list, tuple)):
self._contourLevels = []
levs2 = self._gm.levels
if numpy.allclose(levs2[0], 1.e20):
levs2[0] = 0
for i in range(len(levs2) - 1):
self._contourLevels.append([levs2[i], levs2[i+1]])
# Contour colors:
self._contourColors = self._gm.fillareacolors
if self._contourColors is None:
# TODO BUG levs2 may not be defined here...
self._contourColors = vcs.getcolors(levs2, split=0)
开发者ID:devarajun,项目名称:uvcdat,代码行数:33,代码来源:boxfillpipeline.py
示例3: vcs_colors
def vcs_colors(self):
"""Used internally, don't worry about it."""
levs = self.levels
if self._gm.fillareacolors:
colors = self._gm.fillareacolors
return colors
else:
real_levs = levs
if self.ext_left:
levs = levs[1:]
if self.ext_right:
levs = levs[:-1]
colors = vcs.getcolors(levs, colors=range(self.color_1, self.color_2))
levs = real_levs
if len(colors) < len(levs):
# Pad out colors to the right number of buckets
diff = len(levs) - len(colors)
colors += diff * colors[-1:]
return sorted(colors)
开发者ID:sampsonbryce,项目名称:cdatgui,代码行数:19,代码来源:legend.py
示例4: _updateContourLevelsAndColorsGeneric
def _updateContourLevelsAndColorsGeneric(self):
# Contour values:
self._contourLevels = self._gm.levels
if numpy.allclose(self._contourLevels[0], [0., 1.e20]) or \
numpy.allclose(self._contourLevels, 1.e20):
levs2 = vcs.mkscale(self._scalarRange[0],
self._scalarRange[1])
if len(levs2) == 1: # constant value ?
levs2 = [levs2[0], levs2[0] + .00001]
self._contourLevels = []
if self._gm.ext_1:
# user wants arrow at the end
levs2[0] = -1.e20
if self._gm.ext_2:
# user wants arrow at the end
levs2[-1] = 1.e20
for i in range(len(levs2) - 1):
self._contourLevels.append([levs2[i], levs2[i + 1]])
else:
if not isinstance(self._gm.levels[0], (list, tuple)):
self._contourLevels = []
levs2 = self._gm.levels
if numpy.allclose(levs2[0], 1.e20):
levs2[0] = -1.e20
for i in range(len(levs2) - 1):
self._contourLevels.append([levs2[i], levs2[i + 1]])
else:
levs2 = self._gm.levels
if isinstance(self._contourLevels, numpy.ndarray):
self._contourLevels = self._contourLevels.tolist()
# Figure out colors
self._contourColors = self._gm.fillareacolors
if self._contourColors == [1] or self._contourColors is None:
# TODO BUG It's possible that levs2 may not exist here...
self._contourColors = vcs.getcolors(levs2, split=0)
if isinstance(self._contourColors, (int, float)):
self._contourColors = [self._contourColors]
开发者ID:chaosphere2112,项目名称:uvcdat,代码行数:39,代码来源:pipeline2d.py
示例5: histogram
def histogram(canvas, values, xaxis=None, yaxis=None):
fa = canvas.createfillarea()
t = canvas.gettemplate("default")
fa.viewport = [t.data.x1, t.data.x2, t.data.y1, t.data.y2]
num_fills = len(values)
fa.color = vcs.getcolors(range(num_fills))
x, y = [], []
for i in range(num_fills):
point1, point2 = i / float(num_fills), (i + 1) / float(num_fills)
xl = [point1, point1, point2, point2]
yl = [0, values[i], values[i], 0]
x.append(xl)
y.append(yl)
fa.x = x
fa.y = y
outline = vcs.createline(source="default")
outline.viewport = fa.viewport
outline.x = x
outline.y = y
canvas.plot(fa)
canvas.plot(outline)
开发者ID:chaosphere2112,项目名称:uvcdat_scripts,代码行数:24,代码来源:partition.py
示例6: s
#Filter the variable by lat and long
s = s(lat = (25., 75.6), lon = (25., 85.))
# Initialize a canvas
x = vcs.init()
# Set canvas resolution
# Set canvas colormap
x.setcolormap("bl_to_darkred")
# Set up some levels to filter data by
levs = [-1e20, -5, -4.5, -4, -3.5, -3, -2.5, -2, -1.5, -1, -.5, 0, .5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 1e20]
# Retrieve the colors that would best spread the supplied range of colors
cols = vcs.getcolors(levs, range(239, 11, -1))
# Create and initilize an isofill
iso = x.createisofill()
iso.levels = levs
# Draw the extension arrows on either side of the color legend
iso.ext_1 = "y"
iso.ext_2 = "y"
# Set the fill colors to the ones we retrieved earlier
iso.fillareacolors = cols
# Create a label
txt = x.createtext()
txt.string = "Moscow"
开发者ID:UV-CDAT,项目名称:uvcdat-site,代码行数:30,代码来源:plot_colors.py
示例7:
import sys,cdms2,vcs
x=vcs.init()
f=cdms2.open(vcs.prefix+"/sample_data/clt.nc")
s=f("clt",time=slice(0,23))
#f=cdms2.open(sys.prefix+"/sample_data/sampleCurveGrid4.nc")
#f=cdms2.open(sys.prefix+"/sample_data/sampleGenGrid3.nc")
#s=f("sample")
gm = x.createisofill()
gm = x.createboxfill()
#gm=x.createisoline()
levs = vcs.mkevenlevels(20,80)
gm.levels= levs
gm.fillareacolors = vcs.getcolors(levs)
#gm = x.createmeshfill()
d = x.plot(s,gm)
#d = x.plot(s.filled())
raw_input("Press enter")
x.animate.create(thread_it=False,min=20,max=80)
x.animate.fps(5000)
x.animate.run()
raw_input("Press enter to end")
x.animate.stop()
开发者ID:UNESCO-IHE,项目名称:uvcdat,代码行数:22,代码来源:test_anim_minmax.py
示例8: createTemplateandGM
def createTemplateandGM(x,min,max,deltaisof,deltaisol,days_line,ntemplate=1,orientation='landscape'):
## x.scriptrun('resol_24.scr')
## x.setcolormap('cmap')
dot=x.createline()
dot.type='dot'
if orientation[0].lower()=='p':
x.portrait()
tmpl=x.createtemplate()
## Turns off everything
for a in dir(tmpl):
try:
setattr(getattr(tmpl,a),'priority',0)
except:
pass
## Turns on what we want
tmpl.data.priority=1
tmpl.box1.priority=1
tmpl.legend.priority=1
tmpl.xlabel1.priority=1
tmpl.xlabel2.priority=1
tmpl.ylabel1.priority=2
tmpl.ylabel2.priority=2
tmpl.xtic1.priority=2
tmpl.xtic2.priority=2
tmpl.ytic1.priority=2
tmpl.ytic2.priority=2
tmpl.xname.priority=1
tmpl.yname.priority=1
tmpl.dataname.priority=1
if ntemplate==2:
tmpl.reset('x',.06,.44,tmpl.data.x1,tmpl.data.x2)
else:
tmpl.reset('x',.2,.9,tmpl.data.x1,tmpl.data.x2)
tmpl.reset('y',.2,.9,tmpl.data.y1,tmpl.data.y2)
tmpl.ytic2.x1=tmpl.data.x1
tmpl.ytic2.x2=tmpl.data.x2
tmpl.ytic2.line=dot
to=x.createtextorientation()
to.halign='center'
tmpl.dataname.x=(tmpl.data.x1+tmpl.data.x2)/2.
tmpl.dataname.y=tmpl.data.y2+.03
tmpl.dataname.textorientation=to
tmpl.legend.x1=.3
tmpl.legend.x2=.7
tmpl.yname.x=tmpl.yname.x-.01
tmpl.xname.y=tmpl.xname.y-.075
tmpl.xtic2.y1=tmpl.data.y1
tmpl.xtic2.y2=tmpl.data.y2
tmpl.xtic2.line=dot
tmpl.scalefont(.8)
tmplnoleg=x.createtemplate(source=tmpl.name)
tmplnoleg.legend.priority=0
isof=x.createisofill()
levs2=list(numpy.arange(min,max,deltaisof))
levs1a=list(numpy.arange(min,0,deltaisol))
levs1b=list(numpy.arange(0,max,deltaisol))
isof.levels=levs2
isof.fillareacolors=vcs.getcolors(levs2,colors=range(16,40))
levs1a=list(numpy.arange(min,0,deltaisol))
levs1b=list(numpy.arange(0,max,deltaisol))
isol1=x.createisoline()
isol1.level=levs1a
isol1.label='y'
isol1.line=['dot']
isol2=x.createisoline()
isol2.level=levs1b
isol2.label='y'
tick2={}
for i in days_line:
tick2[1./i]=str(i)+' days'
tick1={}
for i in (0,):
tick1[i]=' '
for gm in [isof,isol1,isol2]:
gm.datawc_x1=-15
gm.datawc_x2=15
gm.datawc_y1=0.
gm.datawc_y2=.8
gm.yticlabels2=tick2
gm.xticlabels2=tick1
return tmpl,tmplnoleg,isof,isol1,isol2
开发者ID:AZed,项目名称:uvcdat,代码行数:96,代码来源:graphics.py
示例9: range
# Initialize canvas:
canvas = vcs.init()
canvas.setbgoutputdimensions(1200,1091,units="pixels")
canvas.drawlogooff()
# Create and plot quick boxfill with default settings:
boxfill=canvas.createboxfill()
# Change the type
boxfill.boxfill_type = 'custom'
levels = range(20,81,10)
boxfill.levels=levels
boxfill.ext_1="y"
boxfill.ext_2="y"
boxfill.fillareacolors=vcs.getcolors(boxfill.levels)
canvas.plot(clt, boxfill, bg=1)
# Load the image testing module:
testingDir = os.path.join(os.path.dirname(__file__), "..")
sys.path.append(testingDir)
import checkimage
# Create the test image and compare:
baseline = sys.argv[1]
testFile = "test_boxfill_custom_ext1_ext2.png"
canvas.png(testFile)
ret = checkimage.check_result_image(testFile, baseline,
checkimage.defaultThreshold)
sys.exit(ret)
开发者ID:devarajun,项目名称:uvcdat,代码行数:30,代码来源:test_boxfill_custom_ext1_ext2.py
示例10: f
pr = f("precip_trend")
x = vcs.init()
vcs.scriptrun(ViridisScript)
colormapname = "bl_to_darkred"
# colormapname = "viridis"
x.setcolormap(colormapname)
iso = x.createisofill()
number_different_colors = 64
levels = numpy.arange(-1., 1.00001, 2. / float(number_different_colors + 1)).tolist()
iso.levels = levels
cols = vcs.getcolors(levels, split=0)
iso.fillareacolors = cols
iso.legend = vcs.mklabels(numpy.arange(-1, 1.01, .125))
# Now create a template to move things around a bit
t = x.createtemplate()
t.xmintic1.priority = 1 # turn on bottom sub ticks
t.xmintic2.priority = 1 # turn on top sub ticks
t.ymintic1.priority = 1 # turn on left sub ticks
t.ymintic2.priority = 1 # turn on right sub ticks
t.scale(.9, "x")
t.scale(1.8, "y")
t.moveto(.05, .1)
# Move legend
开发者ID:OphidiaBigData,项目名称:ophidia-workflow-catalogue,代码行数:31,代码来源:ensemble_analysis.py
示例11: range
sys.path.append(pth)
f=cdms2.open(os.path.join(vcs.sample_data,"clt.nc"))
s=f("clt",slice(0,12)) # read only 12 times steps to speed up things
x=vcs.init()
x.setantialiasing(0)
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")
iso=x.createisoline()
iso.label='y'
levs = range(0,101,10)
iso.level=levs
# add dummy values to levs to get the correct number of cols
cols=vcs.getcolors(levs+[56,])
print levs
print cols
iso.textcolors = cols
iso.linecolors = cols
x.plot(s,iso,bg=1)
x.animate.create()
print "Saving now"
prefix= os.path.split(__file__)[1][:-3]
x.animate.save("%s.mp4"%prefix)
pngs = x.animate.close(preserve_pngs = True) # so we can look at them again
src_pth = sys.argv[1]
pth = os.path.join(src_pth,prefix)
ret = 0
for p in pngs:
print "Checking:",p
开发者ID:UV-CDAT,项目名称:uvcdat,代码行数:31,代码来源:test_vcs_animate_isoline_text_labels_colored.py
示例12: test_portrait
def test_portrait(self):
try:
import vcs
except:
raise RuntimeError(
"Sorry your python is not build with VCS support cannot geenrate portrait plots")
import json
# CDAT MODULES
import pcmdi_metrics
import pcmdi_metrics.graphics.portraits
import MV2
import numpy
from genutil import statistics
import os
import sys
import glob
# CREATES VCS OBJECT AS A PORTAIT PLOT AND LOADS PLOT SETTINGS FOR
# EXAMPLE
x = vcs.init()
x.portrait()
# Turn off antialiasing for test suite
x.setantialiasing(0)
# PARAMETERS STUFF
P = pcmdi_metrics.graphics.portraits.Portrait()
# Turn off verbosity
P.verbose = False
P.PLOT_SETTINGS.levels = [-1.e20, -.5, -.4, -.3, -.2, -.1,
0., .1, .2, .3, .4, .5, 1.e20]
P.PLOT_SETTINGS.x1 = .1
P.PLOT_SETTINGS.x2 = .85
P.PLOT_SETTINGS.y1 = .12
P.PLOT_SETTINGS.y2 = .95
P.PLOT_SETTINGS.xtic2y1 = P.PLOT_SETTINGS.y1
P.PLOT_SETTINGS.xtic2y2 = P.PLOT_SETTINGS.y2
P.PLOT_SETTINGS.ytic2x1 = P.PLOT_SETTINGS.x1
P.PLOT_SETTINGS.ytic2x2 = P.PLOT_SETTINGS.x2
# P.PLOT_SETTINGS.missing_color = 3
# P.PLOT_SETTINGS.logo = None
P.PLOT_SETTINGS.time_stamp = None
P.PLOT_SETTINGS.draw_mesh = 'n'
# P.PLOT_SETTINGS.tictable.font = 3
x.scriptrun(
os.path.join(
pcmdi_metrics.__path__[0],
"..",
"..",
"..",
"..",
"share",
"graphics",
'vcs',
'portraits.scr'))
P.PLOT_SETTINGS.colormap = 'bl_rd_12'
# cols=vcs.getcolors(P.PLOT_SETTINGS.levels,range(16,40),split=1)
cols = vcs.getcolors(P.PLOT_SETTINGS.levels, range(144, 156), split=1)
P.PLOT_SETTINGS.fillareacolors = cols
P.PLOT_SETTINGS.parametertable.expansion = 100
# LIST OF VARIABLES TO BE USED IN PORTRAIT PLOT
vars = [
'pr',
'rsut',
'rsutcs',
'rlutcs',
'tas',
'tos',
'sos',
'zos',
'ua-850',
'ua-200',
'zg-500']
vars = []
# LOAD METRICS DICTIONARIES FROM JSON FILES FOR EACH VAR AND STORE AS A
# SINGLE DICTIONARY
var_cmip5_dics = {}
mods = set()
json_files = glob.glob(
os.path.join(
pcmdi_metrics.__path__[0],
"..",
"..",
"..",
"..",
"share",
"CMIP_metrics_results",
"CMIP5",
"amip",
"*.json"))
#.........这里部分代码省略.........
开发者ID:lee1043,项目名称:pcmdi_metrics,代码行数:101,代码来源:test_portrait.py
示例13: plot
#.........这里部分代码省略.........
# Do we use a predefined meshfill ?
if meshfill is None:
mtics={}
for i in range(100):
mtics[i-.5]=''
icont = 1
meshfill=x.createmeshfill()
meshfill.xticlabels1=eval(data.getAxis(1).names)
meshfill.yticlabels1=eval(data.getAxis(0).names)
meshfill.datawc_x1=-.5
meshfill.datawc_x2=data.shape[1]-.5
meshfill.datawc_y1=-.5
meshfill.datawc_y2=data.shape[0]-.5
meshfill.mesh=self.PLOT_SETTINGS.draw_mesh
meshfill.missing=self.PLOT_SETTINGS.missing_color
meshfill.xticlabels2=mtics
meshfill.yticlabels2=mtics
if self.PLOT_SETTINGS.colormap is None:
self.set_colormap(x)
elif x.getcolormapname()!=self.PLOT_SETTINGS.colormap:
x.setcolormap(self.PLOT_SETTINGS.colormap)
if self.PLOT_SETTINGS.levels is None:
min,max=vcs.minmax(data)
if max!=0: max=max+.000001
levs=vcs.mkscale(min,max)
else:
levs=self.PLOT_SETTINGS.levels
if len(levs)>1:
meshfill.levels=levs
if self.PLOT_SETTINGS.fillareacolors is None:
cols=vcs.getcolors(levs,range(16,40),split=1)
meshfill.fillareacolors=cols
else:
meshfill.fillareacolors=self.PLOT_SETTINGS.fillareacolors
## self.setmeshfill(x,meshfill,levs)
## if self.PLOT_SETTINGS.legend is None:
## meshfill.legend=vcs.mklabels(levs)
## else:
## meshfill.legend=self.PLOT_SETTINGS.legend
# Now creates the mesh associated
n=int(multiple)
ntot=int((multiple-n)*10+.1)
## data=data
sh=list(data.shape)
sh.append(2)
I=MV2.indices((sh[0],sh[1]))
Y=I[0]
X=I[1]
## if ntot>1:
## meshfill.mesh='y'
if ntot == 1:
sh.append(4)
M=MV2.zeros(sh)
M[:,:,0,0]=Y-.5
M[:,:,1,0]=X-.5
M[:,:,0,1]=Y-.5
M[:,:,1,1]=X+.5
M[:,:,0,2]=Y+.5
M[:,:,1,2]=X+.5
M[:,:,0,3]=Y+.5
M[:,:,1,3]=X-.5
M=MV2.reshape(M,(sh[0]*sh[1],2,4))
开发者ID:jkrasting,项目名称:pcmdi_metrics,代码行数:67,代码来源:portraits.py
示例14: cltfile
import vcs, cdms2, os
vcs.download_sample_data_files()
# An example demonstrating patterns with meshfill
cltfile = cdms2.open(os.path.join(vcs.sample_data, "clt.nc"))
clt = cltfile("clt")
canvas = vcs.init()
iso = canvas.createisofill()
iso.fillareastyle = "hatch"
# Refer to http://uvcdat.llnl.gov/examples/pattern_chart.html for a list of patterns
iso.fillareaindices = [1, 2, 3, 4, 5]
iso.levels = [0, 20, 40, 60, 80, 100]
iso.fillareaopacity = [50.0, 85.1, 23.5, 99.9, 100]
iso.fillareacolors = vcs.getcolors(iso.levels)
canvas.plot(clt, iso)
canvas.png("isofill_pattern")
开发者ID:UV-CDAT,项目名称:uvcdat-site,代码行数:20,代码来源:isofill_pattern.py
示例15: finalize
#.........这里部分代码省略.........
if varmin<0 and varmax>0 and hasattr(var,"RMSE"):
mx = max(-varmin,varmax)
#temporarily disabled from dicsussion with J. Potter on 4/28/16
#levels = [float(v) for v in vcs.mkscale( -mx,mx, nlevels, zero=-1 )]
levels = [float(v) for v in vcs.mkscale( varmin,varmax, nlevels, zero=-1 )]
else:
levels = [float(v) for v in vcs.mkscale( varmin, varmax, nlevels, zero=1 )]
# Exceptions occur because mkscale doesn't always work. E.g. vcs.mkscale(0,1.e35,16)
except RuntimeWarning,err:
levels = []
if levels==[]:
## Here's how to do it with percentiles (clip out large values first).
#pc05 = numpy.percentile(self.vars[0],0.05)
#pc95 = numpy.percentile(self.vars[0],0.95)
#levels = [float(v) for v in vcs.mkscale( pc05, pc95, nlevels-2 )]
#levels = [varmin]+levels+[varmax]
# Evenly distributed levels, after clipping out large values:
# This cannot be expected to work always, but it's better than doing nothing.
amed = numpy.median(self.vars[0]._data)
vclip = amed * 1.0e6
logger.warning("Graphics problems, clipping some data at %s",vclip)
self.vars[0]._data[ self.vars[0]._data > vclip ] = vclip
a = numpy.sort(self.vars[0]._data.flatten())
asp = numpy.array_split(a,nlevels)
afirsts = [c[0] for c in asp]+[asp[-1][-1]]
alasts = [asp[0][0]]+[c[-1] for c in asp]
levels = [0.5*(afirsts[i]+alasts[i]) for i in range(len(afirsts))]
levf = levels[0]
levl = levels[-1]
levels = [ round(lv,2) for lv in levels ]
levels[0] = round(1.1*levels[0]-0.1*levels[1],2)
levels[-1] = round(1.1*levels[-1]-0.1*levels[-2],2)
# ... mkscale returns numpy.float64, which behaves unexpectedly in _setlevels when
# passed a tuple value
if levels is not None and len(levels)>0:
self.presentation.levels = levels
if varmin<0 and varmax>0 and hasattr(var,"model"):
self.presentation.fillareacolors=vcs.getcolors(levels,colors=range(16,240),split=1)
#nlevels = max(1, len(levels) - 1)
#self.presentation.list()
#nlrange = range(nlevels+1)
#nlrange.reverse()
#self.presentation.legend = vcs.mklabels( self.presentation.levels )
## Once you set the levels, the VCS default color choice looks bad. So you really
## have to set contour fill colors (integers from 0 through 255) too:
#cmin = 32./nlevels
#cmax = 255./nlevels
## A more flexible way to do what's going on here, thanks to Charles Doutriaux:
## r=10
## g=16
## b=20
## X.setcolorcell(16,r,g,b)
## colors = [16,17,18,...] etc.
## vcs.getcolors is useful, more complicated - see its doc string
#colors = [int(round(a*cmin+(nlevels-a)*cmax)) for a in nlrange]
#self.presentation.fillareacolors = colors
##self.presentation.fillareacolors=[32,48,64,80,96,112,128,144,160,176,240]
elif vcs.isvector(self.presentation) or self.presentation.__class__.__name__=="Gv":
# axis min,max copied from isofill
axaxi = {ax:id for id,ax in self.axax[seqgetattr(var,'id','')].items()}
if 'X' in axaxi.keys() and 'Y' in axaxi.keys():
axx = axaxi['X']
axy = axaxi['Y']
elif 'Y' in axaxi.keys() and 'Z' in axaxi.keys():
axx = axaxi['Y']
axy = axaxi['Z']
self.presentation.datawc_x1 = axmin[axx]
self.presentation.datawc_x2 = axmax[axx]
self.presentation.datawc_y1 = axmin[axy]
self.presentation.datawc_y2 = axmax[axy]
vec = self.presentation
#vec.scale = min(vcsx.bgX,vcsx.bgY)/10.
# Former scale factor, didn't work on more than one variable.
# That is, 100 workrf for moisture transport, 10 for wind stress:
vec.scale = min(vcsx.bgX,vcsx.bgY)/ 100.
if hasattr(self.vars[0],'__getitem__') and not hasattr( self.vars[0], '__cdms_internals__'):
# generally a tuple of variables - we need 2 variables to describe a vector
v = self.vars[0][0]
w = self.vars[0][1]
vm = max(abs(v.min()),abs(v.max()))
wm = max(abs(w.min()),abs(w.max()))
vec.scale = 10 / math.sqrt( math.sqrt( vm**2 + wm**2 ))
else: # We shouldn't get here, but may as well try to make it work if possible:
logger.warning("Trying to make a vector plot without tuples! Variables involved are:")
v = self.vars[0]
v = self.vars[1]
nlats = latAxis(v).shape[0]
nlons = lonAxis(w).shape[0]
# vector density factor of 32 works for moisture transport, 16 for wind stress
nlatvs = vcsx.bgY/32 # how many vectors we want in lat direction
nlonvs = vcsx.bgX/32
#self.strideX = int( 0.9* vcsx.bgX/nlons )
#self.strideY = int( 0.6* vcsx.bgY/nlats )
self.strideX = max(1, int( nlons/nlonvs )) # stride values must be at least 1
self.strideY = max(1, int( nlats/nlatvs ))
开发者ID:UV-CDAT,项目名称:uvcmetrics,代码行数:101,代码来源:uvcdat.py
示例16: get_region_avg
"north_polar": (66, 90),
"north_temperate": (22, 66),
"tropics": (-22, 22),
"south_temperate": (-66, -22),
"south_polar": (-90, -66)
}
def get_region_avg(var, r, axis="xy"):
avg = cdutil.averager(var(latitude=regions[r]), axis=axis)
avg.id = r
return avg
magnitudes = [get_region_avg(averaged_seasons, region) for region in regions]
thetas = [range(4) * 27] * 5
polar = vcsaddons.getpolar("seasonal")
polar.datawc_y1 = 0
polar.datawc_y2 = 100
polar.markers = ["dot"]
polar.markersizes = [3]
polar.markercolors = vcs.getcolors([-90, -66, -22, 22, 66, 90], split=False)
polar.magnitude_tick_angle = numpy.pi / 4
polar.plot(magnitudes, thetas, bg=True, x=x)
fnm = "test_vcs_addons_polar_seasonal.png"
x.png(fnm)
ret = regression.check_result_image(fnm, src)
sys.exit(ret)
开发者ID:UV-CDAT,项目名称:uvcdat,代码行数:30,代码来源:test_vcs_addons_polar_seasonal.py
示例17: levels
canvas = vcs.init()
canvas.bgX = 1500
canvas.bgY = 750
levs = levels(var, partition_count=10)
stat_iso = vcs.createisofill()
int_levs = []
for l in levs:
int_levs.append(int(l))
stat_iso.levels = int_levs
stat_iso.ext_2 = True
stat_iso.ext_1 = True
stat_iso.missing = 1
stat_iso.fillareacolors = vcs.getcolors(stat_iso.levels, split=0)
iso = vcs.createisofill()
v_min, v_max = vcs.minmax(var[0])
scale = vcs.mkscale(v_min, v_max)
iso.levels = scale
iso.ext_2 = True
iso.ext_1 = True
iso.missing = 1
iso.fillareacolors = vcs.getcolors(iso.levels, split=0)
flat = var.flatten().data
stats_variance, stats_binned = calculate_variance(levs, flat)
auto_variance, auto_binned = calculate_variance(scale, flat)
stats_counts = []
auto_counts = []
开发者ID:chaosphere2112,项目名称:uvcdat_scripts,代码行数:30,代码来源:partition.py
示例18: plot
def plot(self, data=None, mesh=None, template=None,
meshfill=None, x=None, bg=0, multiple=1.1):
self.bg = bg
# Create the vcs canvas
if x is not None:
self.x = x
# Continents bug
# x.setcontinentstype(0)
# gets the thing to plot !
if data is None:
data = self.get()
# Do we use a predefined template ?
if template is None:
template = self.generateTemplate()
else:
if isinstance(template, vcs.template.P):
tid = template.name
elif isinstance(template, str):
tid = template
else:
raise 'Error cannot understand what you mean by template=' + \
str(template)
template = vcs.createtemplate(source=tid)
# Do we use a predefined meshfill ?
if meshfill is None:
mtics = {}
for i in range(100):
mtics[i - .5] = ''
meshfill = vcs.createmeshfill()
meshfill.xticlabels1 = eval(data.getAxis(1).names)
meshfill.yticlabels1 = eval(data.getAxis(0).names)
meshfill.datawc_x1 = -.5
meshfill.datawc_x2 = data.shape[1] - .5
meshfill.datawc_y1 = -.5
meshfill.datawc_y2 = data.shape[0] - .5
meshfill.mesh = self.PLOT_SETTINGS.draw_mesh
meshfill.missing = self.PLOT_SETTINGS.missing_color
meshfill.xticlabels2 = mtics
meshfill.yticlabels2 = mtics
if self.PLOT_SETTINGS.colormap is None:
self.set_colormap()
elif self.x.getcolormapname() != self.PLOT_SETTINGS.colormap:
self.x.setcolormap(self.PLOT_SETTINGS.colormap)
if self.PLOT_SETTINGS.levels is None:
min, max = vcs.minmax(data)
if max != 0:
max = max + .000001
levs = vcs.mkscale(min, max)
else:
levs = self.PLOT_SETTINGS.levels
if len(levs) > 1:
meshfill.levels = levs
if self.PLOT_SETTINGS.fillareacolors is None:
if self.PLOT_SETTINGS.colormap is None:
# Default colormap only use range 16->40
cols = vcs.getcolors(levs, list(range(16, 40)), split=1)
else:
cols = vcs.getcolors(levs, split=1)
meshfill.fillareacolors = cols
else:
meshfill.fillareacolors = self.PLOT_SETTINGS.fillareacolors
# Now creates the mesh associated
n = int(multiple)
ntot = int((multiple - n) * 10 + .1)
sh = list(data.shape)
sh.append(2)
Indx = MV2.indices((sh[0], sh[1]))
Y = Indx[0]
X = Indx[1]
if ntot == 1:
sh.append(4)
M = MV2.zeros(sh)
M[:, :, 0, 0] = Y - .5
M[:, :, 1, 0] = X - .5
M[:, :, 0, 1] = Y - .5
M[:, :, 1, 1] = X + .5
M[:, :, 0, 2] = Y + .5
M[:, :, 1, 2] = X + .5
M[:, :, 0, 3] = Y + .5
M[:, :, 1, 3] = X - .5
M = MV2.reshape(M, (sh[0] * sh[1], 2, 4))
elif ntot == 2:
sh.append(3)
M = MV2.zeros(sh)
M[:, :, 0, 0] = Y - .5
M[:, :, 1, 0] = X - .5
M[:, :, 0, 1] = Y + .5 - (n - 1)
M[:, :, 1, 1] = X - 0.5 + (n - 1)
M[:, :, 0, 2] = Y + .5
M[:, :, 1, 2] = X + .5
M = MV2.reshape(M, (sh[0] * sh[1], 2, 3))
#.........这里部分代码省略.........
开发者ID:PCMDI,项目名称:pcmdi_metrics,代码行数:101,代码来源:portraits.py
示例19:
# isofill will use the naive minmax approach
isofill = vcs.createisofill("minmax", "reduced")
# Extract the minimum and maximum levels of sphu
# This will extract the minimum and maximum values from
# all time slices, which may be an issue for your dataset.
# If you want to do an animation, it's a good appraoch.
# If you're just looking at a single time slice, you're better off
# using our automatic level generator.
minval, maxval = vcs.minmax(sphu)
# Automatically create levels based on a minimum and maximum value
# It will round to surround the min and max
isofill.levels = vcs.mkscale(minval, maxval)
# Automatically retrieve colors for the scale
isofill.fillareacolors = vcs.getcolors(isofill.levels)
# isofill2 uses curated levels
# I used the built-in levels, took a look at the visualization, and selected
# the band of values that took up the most space in the heatmap.
isofill2 = vcs.createisofill("manual", "reduced")
isofill2.levels = vcs.mkscale(.2 * 10 ** -5, .5 * 10 ** -5)
# Since there are values outside of the upper and lower bounds I provided,
# let's turn on extensions to allow those values to be accomodated for.
isofill2.ext_1 = True
isofill2.ext_2 = True
isofill2.fillareacolors = vcs.getcolors(isofill2.levels)
# Now we'll drop some labels onto the plots...
plot_titles = vcs.createtext()
开发者ID:UV-CDAT,项目名称:uvcdat-site,代码行数:30,代码来源:iso_levels.py
示例20: f
import vcs
import cdms2
import os
f = cdms2.open(os.path.join(vcs.sample_data, "clt.nc"))
s = f("clt", time=slice(0, 1), squeeze=1)
print s.shape
x = vcs.init()
cmap = x.getcolormap("rainbow")
x.setcolormap("rainbow")
iso = x.createisofill()
levs = [[10, 40], [60, 65], [65, 80], [90, 100]]
cols = vcs.getcolors(levs)
print cols
iso.levels = levs
iso.fillareacolors = cols
x.plot(s, iso)
x.png("contours")
raw_input("Press Enter")
开发者ID:NESII,项目名称:uvcdat,代码行数:20,代码来源:test_contours.py
注:本文中的vcs.getcolors函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论