I was trying to plot a few velocity vectors measured at given points. However I am unable to do this with ListVectorPlot[]
function. I get error each time I try to use it (it says: VisualizationCoreListVectorPlot::vfldata: {{{1,1},{2,2}}}
is not a valid vector field dataset or a valid list of datasets.). Finally I succeeded using Arrow[]
graphics entity, but I'd rather use ListVectorPlot[]
function.
Lets say I have three
points={{1,1},{2,1},{3,1}}
and 2D vectors measured in that points:
vec={{1,0},{0.7,0.1},{1,-0.1}}
How to prepare data to plot this using ListVectorPlot to get such an image:
Code used to plot arrows:
ar = {
Graphics[Arrow[{{1, 1}, {1 + 1, 1 + 0}}]],
Graphics[Arrow[{{2, 1}, {2 + 0.7, 1 + 0.1}}]],
Graphics[Arrow[{{3, 1}, {3 + 1, 1 - 0.1}}]]
};
Show[ar]
Answer
Let me explain the error message first. You assumed that you can give a list of points and vectors and ListVectorPlot
draws exactly those vectors. This is not the case. If you give ListVectorPlot
4 vectors on the corner of the unit-square, it will do the following:
ListVectorPlot[{
{{0, 0}, {1, 1}},
{{1, 0}, {-1, 0}},
{{1, 1}, {-1, -1}},
{{0, 1}, {-1, 0}}}]
See that it interpolates all values in between? And here is the problem with your dataset. All your vectors lie on a line which makes it impossible to create a 2d-plot.
Therefore, are you sure you want to use ListVectorPlot
? What you try can be achieved in one line of code (no matter how many points and vectors you have!)
Graphics[Arrow[{#1, #1 + #2}] & @@@ Transpose[{points, vec}]]
Comments
Post a Comment