From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

2D Vector Plot

Hi,

I would like to perform in LabVIEW the Matlab function of ‘quiver plot’. This is basically a 2D array of vectors, see attached file. Does anyone know how to do this?

The problems that I am having are thus:

Direction is very important so the vectors really need arrow heads on them and I cannot work out how to do this.

Graphs cannot be put into arrays so I will need to know ahead of time how large my plots will be and create all the graphs individually, or I will have to index all the vectors and plot them on one graph. While both of these are possible they are not optimal.

Can anyone help?

Thanks
0 Kudos
Message 1 of 10
(17,070 Views)
I think your best bet is to use a picture indicator. Here you have full control about anything you want to draw, but it will require quite a bit of coding.
(for example, have a look at e.g. the code of the "radar plot" or "smith plot" that ship with LabVIEW.)

Maybe somebody already made such a plot? What is the format of your raw data, e.g. [x, y, length, direction]?)


(AND: Yes, you can put graphs into arrays, you just need to put them into a cluster first, then put the cluster into an array container. However, this is definitely not the way to go.)
0 Kudos
Message 2 of 10
(17,060 Views)
My data is in rectangular form (x,y) but can be easily converted to polar (r, theta).

I would have thought that drawing a vector (with arrow) would be fairly simple.
0 Kudos
Message 3 of 10
(17,058 Views)
Well, polar coordinated won't help much because the arrows are in a rectangular grid. 😉

I think the picture indicator idea should work out just fine. I quickly made an example (LabVIEW 7.1) using some generated data. You can easily make a small subVI that draws an arrow at x,y using the code provided. Of course you would need to scale your data into image coordinates, but that should not be very difficult. Good luck! 🙂

I placed some controls on the front panel so you can adjust arrow head size and tip angle. You can also choose between fixed and proportional head size. Your example has the arrow origins aligned with the grid. I prefer the arrow centers aligned, but you can choose your preference with another control. You might also want to tune some other constants, e.g. max arrow lenght/grid spacing.

Let me know if you don't have LabVIEW 7.1 and I'll convert it down.
Message 4 of 10
(17,049 Views)
Thanks very much altenbach,

This is fantastic! I do not have much experience with graphics so this was a really big help. Now I can go back to my supervisor and say LabVIEW can do everything Matlab can.
Message 5 of 10
(17,039 Views)

Yes, sometimes I am surprised myself about the power of LabVIEW. I really haven't used the picture controls myself much, but this looks useful to explore further. For example you could play with shades of colors!

Rethinking the math, it might be easier to represent the data as 2 complex numbers [Pos(x, y); Arrow( r, theta)]. Now all the math gets a bit simpler on the diagram (no trigonometric functions!).

I have attached a new version that uses complex math. It also colors the arrows according to length from black to red. 🙂

 

Download All
Message 6 of 10
(17,028 Views)
Can you save this as 7.0 format?? Thanks.
0 Kudos
Message 7 of 10
(17,019 Views)
Message 8 of 10
(17,015 Views)
This new program is good. It removes the angle error in the previous version where a theta of 0 was down, not to the right.

I just have two questions. What is the purpose of having centred arrows, I cannot work it out? Secondly is it standard that the y-axis is scaled so that larger values are plotted below smaller values, i.e. the first arrow is plotted in the top left rather than the bottom left? While this is not a problem I was wondering if that was how picture plots were designed.

Thanks again for the program it is exactly what I needed.
0 Kudos
Message 9 of 10
(17,008 Views)
Yes, the picture indicator is (0,0) in the upper left corner.

(I told you that you need to scale your data to picture coordinates, this includes flipping and transposing as needed ;). It is just a linear transformation.)

If you look at the graph that you have posted, the starting point of all arrows is aligned (horizontally and vertically) with the rectangular grid and the arrow only grows on the pointy side. With centered arrows, the center of the arrow is aligned with the grid, the arrow grows in the positive and negative direction.

Arrows that start at 0.0
|->
|--->
|----->
|------->
|--------->
Centered arrows:
    |->
   |--->
  |----->
 |------->
|--------->

Pick whatever is more suitable for your particular application.
0 Kudos
Message 10 of 10
(16,999 Views)