return num_flags,num_barb, half_flag, empty_flag
通过读此方法的说明文档可知,此方法作用为根据输入的风速、设置的短线长线三角的数值计算并返回三角、长线、短线的个数以及有没有无风的情况。 5._make_barbs
def _make_barbs(self, u, v, nflags, nbarbs, half_barb, empty_flag, length, pivot, sizes, fill_empty, flip): '''
This function actually creates the wind barbs. *u* and *v* are components of the vector in the *x* and *y* directions, respectively.
*nflags*, *nbarbs*, and *half_barb*, empty_flag* are, *respectively, the number of flags, number of barbs, flag for *half a barb, and flag for empty barb, ostensibly obtained *from :meth:`_find_tails`.
*length* is the length of the barb staff in points.
*pivot* specifies the point on the barb around which the entire barb should be rotated. Right now, valid options are 'head' and 'middle'.
*sizes* is a dictionary of coefficients specifying the ratio of a given feature to the length of the barb. These features include:
- *spacing*: space between features (flags, full/half barbs)
- *height*: distance from shaft of top of a flag or full barb
- *width* - width of a flag, twice the width of a full barb
- *emptybarb* - radius of the circle used for low magnitudes
*fill_empty* specifies whether the circle representing an empty barb should be filled or not (this changes the drawing of the polygon).
*flip* is a flag indicating whether the features should be flipped to the other side of the barb (useful for winds in the southern hemisphere.
This function returns list of arrays of vertices, defining a polygon for each of the wind barbs. These polygons have been rotated to properly align with the vector direction. '''
# These control the spacing and size of barb elements relative to the # length of the shaft
spacing = length * sizes.get('spacing', 0.125) full_height = length * sizes.get('height', 0.4) full_width = length * sizes.get('width', 0.25) empty_rad = length * sizes.get('emptybarb', 0.15)
# Controls y point where to pivot the barb. pivot_points = dict(tip=0.0, middle=-length / 2.)
# Check for flip if flip:
full_height = -full_height
endx = 0.0
endy = pivot_points[pivot.lower()]
# Get the appropriate angle for the vector components. The offset is # due to the way the barb is initially drawn, going down the y-axis. # This makes sense in a meteorological mode of thinking since there 0 # degrees corresponds to north (the y-axis traditionally) angles = -(ma.arctan2(v, u) + np.pi / 2)
# Used for low magnitude. We just get the vertices, so if we make it # out here, it can be reused. The center set here should put the # center of the circle at the location(offset), rather than at the # same point as the barb pivot; this seems more sensible. circ = CirclePolygon((0, 0), radius=empty_rad).get_verts() if fill_empty:
empty_barb = circ else:
# If we don't want the empty one filled, we make a degenerate # polygon that wraps back over itself empty_barb = np.concatenate((circ, circ[::-1]))
barb_list = []
for index, angle in np.ndenumerate(angles):
# If the vector magnitude is too weak to draw anything, plot an # empty circle instead if empty_flag[index]:
# We can skip the transform since the circle has no preferred # orientation
barb_list.append(empty_barb) continue
poly_verts = [(endx, endy)] offset = length
# Add vertices for each flag for i in range(nflags[index]):
# The spacing that works for the barbs is a little to much for # the flags, but this only occurs when we have more than 1 # flag.
if offset != length: offset += spacing / 2. poly_verts.extend( [[endx, endy + offset],
[endx + full_height, endy - full_width / 2 + offset], [endx, endy - full_width + offset]])
offset -= full_width + spacing
# Add vertices for each barb. These really are lines, but works # great adding 3 vertices that basically pull the polygon out and # back down the line
for i in range(www.tt951.comnbarbs[index]): poly_verts.extend( [(endx, endy + offset),
(endx + full_height, endy + offset + full_width / 2), (endx, endy + offset)])
offset -= spacing
# Add the vertices for half a barb, if needed if half_barb[index]:
# If the half barb is the first on the staff, traditionally it # is offset from the end to make it easy to distinguish from a # barb with a full one if offset == length:
poly_verts.append((endx, endy + offset)) offset -= 1.5 * spacing poly_verts.extend( [(endx, endy + offset),
(endx + full_height / 2, endy + offset + full_width / 4), (endx, endy + offset)])
# Rotate the barb according the angle. Making the barb first and # then rotating it made the math for drawing the barb really easy. # Also, the transform framework makes doing the rotation simple. poly_verts = transforms.Affine2D().rotate(-angle).transform( poly_verts)
barb_list.append(poly_verts)
return barb_list
通过读此方法的说明文档可知,此方法作用为根据输入的风数据以及短线长线三角的个数绘制风羽风向杆。
绘制过程为:判断地图坐标点是不是无风,如果无风就绘制一个空心圆圈代表。如果有风就开始按照三角、长线、短线的顺序绘制。 绘制方法为:
创建一个用于存储关键点坐标的列表poly_verts 计算关键点坐标
通过transform方法将关键点坐标列表中的各个关键点依次用黑线连接起来,最终将风羽风向杆绘制出来 此方法的几个关键变量:
spacing:风羽上短线长线以及三角间的距离 full_height:三角的高度 full_width :三角的宽度 endx :风羽绘制的起始点x坐标 endy:风羽绘制的起始点y坐标 angles:风向杆角度
poly_verts :绘制风羽风向杆的关键点列表
offset:绘制完一个三角或线后下一个三角或线的关键起始坐标 poly_verts = [(endx, endy)] offset = length
# Add vertices for each flag for i in range(nflags[index]):
# The spacing that works for the barbs is a little to much for # the flags, but this only occurs when we have more than 1 # flag.
if offset != length: offset += spacing / 2. poly_verts.extend( [[endx, endy + offset],
[endx + full_height, endy - full_width / 2 + offset], [endx, endy - full_width + offset]])
offset -= full_width + spacing 这一段是绘制风羽的主要代码,利用图片的形式说明
三、绘制空心实心三角
在了解了风羽的绘制过程后,发现可以通过增加关键点直接绘制实心三角,通过原绘制方法绘制空心三角。
相关推荐: