对于数据分布进行分析,例如天气情况。
将学习matplotlib.pyplot.streamplot()方法相关属性的学习,l
ax.streamplot(x_grid, y_grid, x_vec, y_vec, density=spacing)
这里的 x_grid 和y_grid 是x点和y点的数组 x_vec 和*y_vec*表示网格上每个点的流速度.属性#density=spacing#指定要绘制在一起的流线的距离。
什么是流线图?
流线图通过流线和箭头的组合绘制,来表示某一时段流线的运行情况、
流线图上的箭头表示流向,流线上的形状表示流强度
流线图可分为气流图、等风速线、变高图等
流线图中的流线可以合并、汇合、分交,但不能交叉
流线图通常用于气象学中研究风速、气流、洋流的流向情况
流程图是风场分析的重要图表,流线的稀密度与风速大小成正比
获取流线图方法
设置流线图密度
取值类型为:浮点型或者元组
控制流线图密度,当density=1时,网格会被划分为30*30网格
对于设置每个方向上密度,可以使用元组(x,y)
取值类型为:浮点型或者二维数组
使用二维数组,可以改变流线在网格上的线宽
阵列的形状必须要与u、v相同
取值可为:
表示颜色的英文单词:如绿色"g"
表示颜色单词的简称如:红色"r",黄色"y"
RGB格式:十六进制格式如"#88c999";(r,g,b)元组形式
可以转入颜色列表
当使用cmap时,则需要color设置为二维数组,否则无效
默认为将流线拉伸到(0,1)
仅在颜色为数组时使用
'''
Created on 2023年4月3日
@author: admin
'''
import numpy as np
import matplotlib.pyplot as plt
w = 3
Y, X = np.mgrid[-w:w:100j, -w:w:100j]
U = -1 - X**2 + Y
V = 1 + X - Y**2
speed = np.sqrt(U**2 + V**2)
fig, axs = plt.subplots(3, 2, figsize=(7, 9),
gridspec_kw={'height_ratios': [1, 1, 2]}
)
axs = axs.flat
axs[0].streamplot(X, Y, U, V, density=[0.5, 1])
axs[0].set_title('Varying Density')
strm = axs[1].streamplot(X, Y, U, V, color=U, linewidth=2, cmap='autumn')
fig.colorbar(strm.lines)
axs[1].set_title('Varying Color')
lw = 5*speed / speed.max()
axs[2].streamplot(X, Y, U, V, density=0.6, color='k', linewidth=lw)
axs[2].set_title('Varying Line Width')
seed_points = np.array([[-2, -1, 0, 1, 2, -1], [-2, -1, 0, 1, 2, 2]])
strm = axs[3].streamplot(X, Y, U, V, color=U, linewidth=2,
cmap='autumn', start_points=seed_points.T)
fig.colorbar(strm.lines)
axs[3].set_title('Controlling Starting Points')
axs[3].plot(seed_points[0], seed_points[1], 'bo')
axs[3].set(xlim=(-w, w), ylim=(-w, w))
mask = np.zeros(U.shape, dtype=bool)
mask[40:60, 40:60] = True
U[:20, :20] = np.nan
U = np.ma.array(U, mask=mask)
axs[4].streamplot(X, Y, U, V, color='r')
axs[4].set_title('Streamplot with Masking')
axs[4].imshow(~mask, extent=(-w, w, -w, w), alpha=0.5, cmap='gray',
aspect='auto')
axs[4].set_aspect('equal')
axs[5].streamplot(X, Y, U, V,)
axs[5].set_title('Streamplot with unbroken streamlines')
plt.tight_layout()
plt.show()
页面更新:2024-05-16
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号