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: 

XY graph multi plot live points and colour control

Solved!
Go to solution

Hi All,

 

I'm trying to do something that should be simple but is proving to be difficult so far. I have had a good look through previous topics and found things similar but not actually what I want.

 

In my experiment I scan intensity vs wavelength.

 

Ideally I want to be able to:

 

1)  run a scan and see the points plotted live.

 

2) Then I want the plot to stay on the graph when I run the next scan, etc.

 

3) I'd like to do an arbitrary number of scans. e.g. To initiate a scan I press a button, an arbitrary number of times.  

 

4) I want to make it so that the current scan is plotted live in one colour (red), and all the previous scans remain plotted in another colour (blue).

 

5) Sometimes I may want to clear the graph of all scans and begin again, without having to stop the VI.

 

Items 1-3 can be taken care of easily by placing the Build XY graph and XY graph object inside the for loop that runs the scan, and unticking 'Clear data on each call' in the propertes of Build graph. See first attached VI.

 

However, at the beginning of a scan it joins the last point of the previous scan to the first point of the next scan.

 

The difficult parts are 4 and 5.

 

For item 4 you need to build an array of plots, which is easy if you know the number of plots, but here the number is arbitrary. So how do I do that? I've had a go by trying to use Insert Array in different ways but I haven't worked it out. Then hopefully using the XY graph property nodes I can set the colours of the plots.

 

For part 5 it is not enough just to use the invoke node = reinitialize to default, and have a button that executes the node. This clears the graph but then when you run the next scan all the previous plots pop up again, indicating that the array that stores the plots is not actually cleared. The second attachment shows how I'm clearing the graph.

 

My biggest problem is item 4, and combining item 4 and 5 together.

 

Please help. 

 

  

Download All
0 Kudos
Message 1 of 14
(5,326 Views)

The key is understanding the data type. If you hover over the graph's terminal, you will see that multiple plots are simply an array of single plots. Once you know that, something like this quick modification is fairly easy to come up with. I also added events to make it more readable. Note that this isn't actually a good way of doing things (for instance, you can't abort the drawing in the middle), but it shows the graph concept. You might wish to look at some code like producer/consumer designs.

 

As for the colors, you're right that the properties can help you there. I will leave it to you to figure out the exact properties, but when you start a new plot, you will basically want to reset all the others to white and make the new one red.

 

 


___________________
Try to take over the world!
0 Kudos
Message 2 of 14
(5,317 Views)

tst,

 

Thank you for this response.

 

I should have mentioned in the first post that I'm using LV 2011 Base, which does not have the event structure unfortunately. Also I did not specify in the problem but it's very useful and sometimes necessary to abort the scan.

 

I am aware of the data type that I need, I think my trouble is getting the plot data into the right form.

 

Really all I need to do is send the bundle that contains the XY values into a new row of a 2D array (of arrays). I have found this task more difficult than expected. It would be easy if the number of scans was known, because you could initialize an array of that size and just keep passing it through, inserting the bundled XY data into the row equaling the number of counter that counts how many times you press the scan button.

 

So in a nutshell, my problem is adding an array to a new row of an array of arrays an arbitrary number of times.  

0 Kudos
Message 3 of 14
(5,299 Views)

You can't have an array of arrays. If you look at the code, you will see that the data type you need is an array of a cluster of arrays.

 

Even if you can't modify event structures, you can still read the code and modify it. The key is making sure everyone works on the same data. The easiest modification is to move everything back to a simple loop, like you had before. In such a case, you need to put the cases one after the other, so that the output of one case (the array of clusters) serves as the input to the next case, like so:

 

XY Chart_BD.png

 

 

 

A better option would be to keep the basic structure of the loop and replace the event structure with something else which you can use, such as a queue. Like I said, look at the examples.

 

Also, if you can upgrade to LV 2012, the base version there allows editing event structures, which is highly recommended for creating proper programs.

 


___________________
Try to take over the world!
0 Kudos
Message 4 of 14
(5,292 Views)

This code from a different thread written by someone else does almost what I want but not quite because it needs the total number of plots as input before execution. My trouble is I don't know the total number of plots to begin with. I could just make it a large number but that seems crude.

0 Kudos
Message 5 of 14
(5,276 Views)

I have modified my code and now it does everything I wanted above, except for specifying the colours.

 

It's probably not the best ever code and as I've mentioned I do not have access to the event structure to make it better, but it works.

 

Thanks

0 Kudos
Message 6 of 14
(5,266 Views)

Sorry, forgot to attach the updated VI

0 Kudos
Message 7 of 14
(5,264 Views)

You should be able to know the number of plots because you add one plot each time. You even have a counter in your code which you increment, so that it keeps this value (although if your data type was better, you could just check the size of the array). All you really need to do is iterate over the plots and set their colors. The relevant properties would be Active Plot and Plot.Color (and possibly Legend.NumRows, because I think LV doesn't allow you to modify a plot before it's drawn or shown on the legend).

 

I should point out that there's a serious issue in your code - you take all the channels you already had, swap out the first one with the new data and then add the entire list to the end of the existing channnels. This effectively duplicates your entire data set each time, which is extermely inefficient and could cause you to run out of memory (and means that your data doesn't actually reflect your channels correctly). My suggestion would be to do it like I did in my code (add an empty plot to the array when you add it and work on it) or work on a single plot in the for loop instead of the entire array.


___________________
Try to take over the world!
0 Kudos
Message 8 of 14
(5,257 Views)

Thank you for pointing out the defect in my code. I agree I should do something like you've suggested, adding a new plot. I was not aware that I was duplicating the set.

0 Kudos
Message 9 of 14
(5,254 Views)
Solution
Accepted by topic author Mattetc

I have fixed up the problem of the plot array doubling, and added in the desired plot colouring, attached.

 

The code now does everything that I wanted in my first post.

 

 

No doubt the code could be improved more, but there it is for anyone else out there that has this problem.

 

Thankyou to tst for providing me useful hints.    

0 Kudos
Message 10 of 14
(5,228 Views)