LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CHANGING PLOT COULOURS IN XY GRAPH AFTER CERAIN POINTS

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. Untitled.png

 

0 Kudos
Message 1 of 7
(195 Views)

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

0 Kudos
Message 2 of 7
(173 Views)

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....

 

altenbach_0-1739653556183.png

altenbach_1-1739653563999.png

 

 

Message 3 of 7
(159 Views)

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:

TEST Two Colors.png

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:

TEST 2-Color Chart.png

 

Bob Schor 

 

0 Kudos
Message 4 of 7
(137 Views)

Well, a chart seems not right, because x start over from zero for each iteration of the outer loop.

0 Kudos
Message 5 of 7
(132 Views)

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:

  • Replace the "fixed data" For Loop of 100 points with a While Loop that runs until the Stop button is pressed.  Instead of a linear ramp which is more-or-less unbounded, replace the "data being plotted" with a sinusoid whose period is maybe 25 points (so you will get 4 cycles in a Chart with 100 points).
    • A "Learning Issue" is how do you set the width of the Chart?  How did I "fix it" to be 100 points?
  • Change my "Chart" demo with a "Graph" demo.  Start by moving the Chart (inside the For loop) to a Graph outside the For Loop.  Since you won't see anything until all 100 points are plotted, you might as well get rid of the "Wait (ms)" timer which is only there to let you see the colors change as the plot evolves, a "Chart", but not a "Graph", property.  [You could plot a Graph of 1 point, replot it as a Graph of 2 points, replot it as a Graph of 3 points, ... but that seems like a silly waste of CPU and other resources.]
  • Study and understand what the computations being done before the Case statement inside the loop do.  What would happen if you changed some of the numeric values?
  • How would you modify this code to accomodate a "Color" control (which could be a Boolean, White/Red) to let the Color change based on some condition elsewhere in your program?

Bob Schor

0 Kudos
Message 6 of 7
(105 Views)

Yes, there are plenty of similar solutions, e.g. here:

 

altenbach_0-1739731583000.png

 

 

An example switching color based on Y value is here:

 

TwoColorXY.png

 

For full color control and intensity graph (or chart if desired) gives access to any color (example).

 

ColorGraph.png

 

 

 

 

Message 7 of 7
(93 Views)