vector¶
# Vector (Gv) module
-
class
vcs.vector.
Gv
(Gv_name, Gv_name_src='default')[source]¶ The vector graphics method displays a vector plot of a 2D vector field. Vectors are located at the coordinate locations and point in the direction of the data vector field. See scaletype for how the lengh of a vector on the screen is determined.
The example below shows how to modify the vector’s line, scale, alignment, type, and reference.
This class is used to define an vector table entry used in VCS, or it can be used to change some or all of the vector attributes in an existing vector table entry.
-
Useful Functions:
1 2 3 4 5 6 7 8 9 10 11 12
# Constructor a=vcs.init() # Show predefined vector graphics methods a.show('vector') # Show predefined VCS line objects a.show('line') # Change the VCS color Map a.setcolormap("AMIP") # Plot data 's1', and 's2' with vector 'v' and 'default' template a.vector(s1, s2, v,'default') # Updates the VCS Canvas at user's request a.update()
-
Make a Canvas object to work with:
a=vcs.init()
-
Create a new instance of vector:
1 2 3 4
# Copies content of 'quick' to 'new' vc=a.createvector('new','quick') # Copies content of 'default' to 'new' vc=a.createvector('new')
-
Modify an existing vector:
vc=a.getvector('AMIP_psl')
-
Overview of vector attributes:
List all attributes:
# Will list all the vector attribute values vc.list()
Set axis attributes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
# Can only be 'linear' vc.projection='linear' lon30={-180:'180W',-150:'150W',0:'Eq'} vc.xticlabels1=lon30 vc.xticlabels2=lon30 # Will set them both vc.xticlabels(lon30, lon30) vc.xmtics1='' vc.xmtics2='' # Will set them both vc.xmtics(lon30, lon30) vc.yticlabels1=lat10 vc.yticlabels2=lat10 # Will set them both vc.yticlabels(lat10, lat10) vc.ymtics1='' vc.ymtics2='' # Will set them both vc.ymtics(lat10, lat10) vc.datawc_y1=-90.0 vc.datawc_y2=90.0 vc.datawc_x1=-180.0 vc.datawc_x2=180.0 # Will set them all vc.datawc(-90, 90, -180, 180) xaxisconvert='linear' yaxisconvert='linear' # Will set them both vc.xyscale('linear', 'area_wt')
Specify the line style:
1 2 3 4 5 6 7 8 9 10
# Same as vc.line='solid' vc.line=0 # Same as vc.line='dash' vc.line=1 # Same as vc.line='dot' vc.line=2 # Same as vc.line='dash-dot' vc.line=3 # Same as vc.line='long-dot' vc.line=4
Specify the line color of the vectors:
1 2 3 4
# Color range: 16 to 230, default line color is black vc.linecolor=16 # Width range: 1 to 100, default size is 1 vc.linewidth=1
Specify the vector scale factor:
# Can be an integer or float vc.scale=2.0
Specify the vector alignment:
1 2 3 4 5 6
# Same as vc.alignment='head' vc.alignment=0 # Same as vc.alignment='center' vc.alignment=1 # Same as vc.alignment='tail' vc.alignment=2
Specify the vector type:
1 2 3 4 5 6
# Same as vc.type='arrow head' vc.type=0 # Same as vc.type='wind barbs' vc.type=1 # Same as vc.type='solid arrow head' vc.type=2
Specify the vector reference:
1 2 3 4 5
# Can be an integer or float. Setting the reference attribute # overrides the default behavior of picking a reasonable size # for the vector legend arrow. This may result in a very large # or very small arrow, depending on the value of vc.reference. vc.reference=4
-
property
alignment
¶ One of the following strings: off - No scaling is performed on the vector values constant: vector value * self.scale normalize: vector value / max_norm constantNNormalize: vector value * self.scale / max_norm linear: map [min_norm, max_norm] to self.scalerange constantNLinear - map [min_norm, max_norm] to self.scalerange and then multiply by self.scale
-
script
(script_filename=None, mode=None)[source]¶ Saves out a copy of the vector graphics method, in JSON or Python format to a designated file.
Note
If the the filename has a ‘.py’ at the end, it will produce a Python script. If no extension is given, then by default a .json file containing a JSON serialization of the object’s data will be produced.
Warning
VCS Scripts Deprecated. SCR script files are no longer generated by this function.
- Example
1 2 3 4
>>> a=vcs.init() >>> ex=a.getvector() >>> ex.script('filename.py') # append to 'filename.py' >>> ex.script('filename','w') # make/overwrite 'filename.json'
- Parameters
script_filename (str) – Output name of the script file. If no extension is specified, a .json object is created.
mode (str) – Either ‘w’ for replace, or ‘a’ for append. Defaults to ‘a’, if not specified.
-