1.实心三角绘制
实心三角绘制代码
# 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/4, endy - full_width / 8 + offset], [endx, endy - full_width / 8 + offset],
[endx + full_height/4, endy - full_width / 8 + offset], [endx + full_height/2, endy - full_width / 4 + offset], [endx, endy - full_width / 4 + offset],
[endx + full_height/2, endy - full_width / 4 + offset], [endx + 3*full_height/4, endy - 3*full_width / 8 + offset], [endx, endy - 3*full_width / 8 + offset],
[endx + 3*full_height/4, endy - 3*full_width / 8 + offset], [endx + full_height, endy - full_width / 2 + offset], [endx,endy-full_width/2+offset],
[endx + full_height, endy - full_width / 2 + offset], [endx + 3*full_height/4, endy - 5*full_width / 8 + offset], [endx, endy - 5*full_width / 8 + offset],
[endx + 3*full_height/4, endy - 5*full_width / 8 + offset], [endx + full_height/2, endy - 3*full_width / 4 + offset], [endx, endy - 3*full_width / 4 + offset],
[endx + full_height/2, endy - 3*full_width / 4 + offset], [endx + full_height/4, endy - 7*full_width / 8 + offset], [endx, endy - 7*full_width / 8 + offset],
[endx + full_height/4, endy - 7*full_width / 8 + offset], [endx, endy - full_width + offset]])
offset -= full_width + spacing 实心三角绘制示意图
方法参数中加入nfullflags
def _make_barbs(self, u, v, nfullflags, nflags,nbarbs, half_barb, empty_flag, length,pivot, sizes, fill_empty, flip): '...'
2.实心三角个数计算
def _find_tails(self, mag, rounding=True, half=2, full=4, flag=20,fullflag=50): '''
Find how many of each of the tail pieces is necessary. Flag specifies the increment for a flag, barb for a full barb, and half for half a barb. Mag should be the magnitude of a vector (i.e., >= 0).
This returns a tuple of:
(*number of flags*, *number of barbs*, *half_flag*, *empty_flag*)
*half_flag* is a boolean whether half of a barb is needed, since there should only ever be one half on a given barb. *empty_flag* flag is an array of flags to easily tell if a barb is empty (too low to plot any barbs/flags. '''
# If rounding, round to the nearest multiple of half, the smallest # increment if rounding:
mag = half * (mag / half + 0.5).astype(np.int)
num_fullflags = np.floor(mag / fullflag).astype(np.int) mag = np.mod(mag, fullflag)
num_flags = np.floor(mag / flag).astype(np.int) mag = np.mod(mag, flag)
num_barb = np.floor(mag / full).astype(np.int) mag = np.mod(mag, full)
half_flag = mag >= half
empty_flag = ~(half_flag | (num_flags > 0) | (num_fullflags > 0) |(num_barb > 0))
return num_fullflags,num_flags,num_barb, half_flag, empty_flag 3. 调整set_UVC中相关方法使用
fullflags, flags,barbs, halves, empty = self._find_tails(magnitude, self.rounding,
**self.barb_increments)
# Get the vertices for each of the barbs
plot_barbs = self._make_barbs(u, v, fullflags, flags,barbs, halves, empty,
self._length, self._pivot, self.sizes, self.fill_empty, self.flip) 四、测试
import matplotlib.pyplot as plt
fig=plt.figure()
ax=fig.add_subplot(111); ax.axis([-1,1,-1,1]) ax.set_xticks([]) ax.set_yticks([])
ax.barbs(0,0,30*1.5,40*1.5,length=8,linewidth=0.5)
plt.show()
相关推荐: