02-15-2025 03:27 AM
I have a program where have two for loops nested. In the inner for loop I collect data and plot it immediately. When the iterations of the inner loop have ended and a new iteration of the outer loop begins. I aim to change the colour of the plot so that I can know the difference.
I have attached the VI and also the picture of the same.
02-15-2025 09:23 AM
If you are making a single plot (i.e. wiring a single point or a single array of points to a graph or chart), you cannot change the color of the points being plotted. You can put an "indicator" that something has changed by plotting a "blank space" where the plot changes (the cost, of course, is you sacrifice a few points). To do this, you need to be plotting floating point quantities -- if you plot "NaN" (Not a Number, found on the Numeric Palette), it "doesn't plot".
If you really want to plot in two colors, you need to create two plots, let's call them Red and Green. For simplicity, I'm going to assume you are generating plots one point at a time. When you want a point to be plotted in Red, put the point value out on the Red plot and NaN on the Green plot. To plot Green, reverse the order.
Bob Schor
02-15-2025 02:57 PM - edited 02-15-2025 03:06 PM
You are using the express VI set to not clear data between calls, so it is more like a chart.
I assume you want a graph with three plots of 10 points each, so initialize an array with this size filled with NaN and replace values as you go.
Since your x values are equally spaced, you don't need an xy graph.
See if this can give you some ideas....
02-15-2025 09:42 PM
Well, I went with a Chart (instead of a Graph) because I wanted to plot a single line (I chose the line Y = X, where X goes from 0 to 99 (100 points). I generate 10 points a second, so you can watch the line evolve. Here's the result:
So how did I do this? I used a For Loop to generate 100 points. I plotted them 10 at a time in a Cluster of 2 Dbls, alternating data points and NaN every 10 points.
Here's the simple code:
Bob Schor
02-15-2025 09:49 PM
Well, a chart seems not right, because x start over from zero for each iteration of the outer loop.
02-16-2025 07:59 AM
Sigh. This is a "proof-of-concept" showing (dynamically) plot colors changing as the data are generated and plotted. Yes, it does not address the exact question that was asked (and is the title of this thread), but having first made a "Graph" demo, the static nature ("Allakazam -- a white-and-red line suddenly appears") seemed less satisfying than watching the line being drawn.
Interesting exercises for the curious LabVIEW Learner:
Bob Schor
02-16-2025 12:49 PM
Yes, there are plenty of similar solutions, e.g. here:
An example switching color based on Y value is here:
For full color control and intensity graph (or chart if desired) gives access to any color (example).