第一范文网 - 专业文章范例文档资料分享平台

Python自学笔记 - Matplotlib风羽自定义

来源:用户分享 时间:2025/8/17 8:02:26 本文由钀屽皬鑺� 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

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()

搜索更多关于: Python自学笔记 - Matplotlib风羽自定义 的文档
Python自学笔记 - Matplotlib风羽自定义.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c52ww780ele37lyd0yjbf83hrt8bf1m008rz_3.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top