How to| 绘制矢量场
矢量场的可视化可以通过在常规网格上绘制矢量,绘制选定的流线图,或使用渐变配色方案表示矢量和流线密度来实现. 此外您也可以由相对于一个映射的矢量列表绘制矢量场.
使用 VectorPlot 绘制矢量场中的矢量,矢量场由
至
的映射给定:
VectorPlot[{x, -y}, {x, -3, 3}, {y, -3, 3}]使用 StreamPlot 绘制流线:
StreamPlot[{x, -y}, {x, -3, 3}, {y, -3, 3}]使用 StreamPoints 选项绘制选定的流线:
StreamPlot[{x, -y}, {x, -3, 3}, {y, -3, 3}, StreamColorFunction -> None, StreamPoints -> {{{{-2, 1}, Green}, {{0.5, -1}, Red}}}]使用 StreamPoints 选项选择图形中的流线:
StreamPlot[{x, -y}, {x, -3, 3}, {y, -3, 3}, StreamColorFunction -> None, StreamPoints -> {{{{-2, 1}, Green}, {{0.5, -1}, Red}, Automatic}}]使用 VectorDensityPlot 和 StreamDensityPlot 实现场密度的可视化:
VectorDensityPlot[{x, -y}, {x, -3, 3}, {y, -3, 3}]StreamDensityPlot[{x, -y}, {x, -3, 3}, {y, -3, 3}, ColorFunction -> "ThermometerColors"]使用 VectorPlot3D 绘制一个三维矢量场(矢量颜色由其大小决定):
VectorPlot3D[{x, y, z}, {x, -3, 3}, {y, -3, 3}, {z, -3, 3}, VectorColorFunction -> "DeepSeaColors"]在 Wolfram 语言中,您不仅可以绘制矢量场,也可以对这些图形进行微调. 下面的示例介绍了一些可以应用的选项.
使用 VectorStyle 改变 VectorPlot 中的箭头类型:
VectorPlot[{ y, -x}, {x, -3, 3}, {y, -3, 3}, VectorStyle -> {StandardGray, "Disk"}, VectorColorFunction -> None]使用 StreamPoints 控制图形中的流线数量:
{StreamPlot[{x, -y}, {x, -3, 3}, {y, -3, 3}, StreamPoints -> Coarse], StreamPlot[{x, -y}, {x, -3, 3}, {y, -3, 3}, StreamPoints -> Fine]}StreamPlot[{x, -y}, {x, -3, 3}, {y, -3, 3}, VectorPoints -> Automatic, VectorColorFunction -> None, StreamColorFunction -> None, StreamStyle -> Orange]使用 ColorFunction 应用一个基于矢量与流线密度的颜色方案:
StreamDensityPlot[{x, -y}, {x, -3, 3}, {y, -3, 3}, StreamColorFunction -> None, StreamStyle -> Black, VectorPoints -> Automatic, VectorColorFunction -> None, VectorStyle -> White, ColorFunction -> "Rainbow"]可以使用 VectorColorFunction 选择一个颜色方案,并指定一个函数为矢量着色. 这里绘制的两个图形使用"DarkRainbow" 颜色方案着色,各个图形根据的是在 VectorColorFunction 指定的函数:
{VectorPlot[{ y, -x}, {x, -3, 3}, {y, -3, 3}, VectorStyle -> "Disk", VectorColorFunction -> {"DarkRainbow", Function[{x, y}, x]}], VectorPlot[{ y, -x}, {x, -3, 3}, {y, -3, 3}, VectorStyle -> "Disk", VectorColorFunction -> {"DarkRainbow", Function[{x, y}, x + y]}]}由于在 VectorColorFunction 所用中的一些函数是常见的,Wolfram 语言允许您将它们称为变量. 这些变量用由 1 至 5 的整数表示,其中 1 为
变量,2 为
变量,3 为第一个场分量,4 为第二个场分量,5 为向量的大小. 如要指定这些变量,将 #n& 与 VectorColorFunction 联用,其中 n 表示变量的编号.
根据第二个场分量 (#4&) 给图形着色,使用 "DarkRainbow" 颜色方案:
VectorPlot[{ y, -x}, {x, -3, 3}, {y, -3, 3}, VectorStyle -> "Disk", VectorColorFunction -> {"DarkRainbow", #4&}]根据矢量大小(#5&)给图形着色,同样使用 "DarkRainbow" 颜色方案:
VectorPlot[{ y, -x}, {x, -3, 3}, {y, -3, 3}, VectorStyle -> "Disk", VectorColorFunction -> {"DarkRainbow", #5&}]StreamPlot[{x, -y}, {x, -3, 3}, {y, -3, 3}, StreamColorFunction -> None, StreamPoints -> {{{{-1, 2}, Green}}, Automatic, {Forward, Automatic}}]使用 VectorStyle 得到 VectorPlot3D 中的三维效果:
VectorPlot3D[{x, y, z}, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, VectorScaling -> Automatic, VectorColorFunction -> None, VectorStyle -> Red]用 VectorMarkers 指定标记:
VectorPlot3D[{x, y, z}, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, VectorMarkers -> "Arrow"]相关演示
- Vector Fields: Plot Examples
- Visualizing Vector Fields
- Flow of a Vector Field in 2D
- Vector Fields: Streamline through a Point
- Sources, Saddle Points, and Sinks in Vector Fields
- 3D Vector Fields
- Vector Field Flow through and around a Circle
- Families of Solutions for ODEs
- Integrating a Vector Field along a Curve