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"カラースキームで2つのプロットに色付けする.それぞれのプロットは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は第1の場の成分,4は第2の場の成分,そして5はベクトルの絶対値である.これらの変数を指定するには,#n&(nは変数の番号を表す)をVectorColorFunction と一緒に使う.
第2の場の成分(#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