LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Automatically labeling plot legend using XY Graphs?

Solved!
Go to solution

I want to plot:

Time Amp

1       2

2       4

3       9

 

How do I get the legend to automatically say Amp, instead of Plot 0? I went to property node -> legend and I don't see any option

that would read the "column" header and label the legend accordingly.

 

In my example, the X array (Time) and Y array (Amp) are fed into Bundle which is then fed to the XY Graph input. The X array (1,2,3) and Y array (2,4,9)

obviously carry no information about their respective column names (Time, Amp). So, the legend must read this information separately, but I don't know

how to feed this information to the plot legend. 

0 Kudos
Message 1 of 18
(6,502 Views)
Solution
Accepted by topic author murchak

You simply need a property node for "plot.name". You have only one plot, so the following is sufficient (of course you would replace the string diagram constant with whatever you read from the column header in the file)

 

 

 

(If you have several plots, you would do it in a loop, setting the active plot from the iteration terminal, first, then writing the name)

 

Since this is an xy graph, I would actually hide the legend and simply label the two axes according to their header. This can be done in a similar way with property nodes. See if you can figure it out. 😉

 

 

(Of course if the labels never change, enter them once manually and they will be saved with the VI. No code needed.)

Message 2 of 18
(6,498 Views)

Thank you very much!

0 Kudos
Message 3 of 18
(6,494 Views)

While we're on this topic, suppose I had a 3rd column which are error bars for Amp. At each X (Time) value the Y (Amp) could have a different error. Is there an easy way to plot these error bars?

0 Kudos
Message 4 of 18
(6,490 Views)

Hi murchak,

 

as you asked for an easy way: try the error bar plot from the graph control palette...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 18
(6,477 Views)

Thank you GerdW.

 

I was able to plot two curves on the same plot with the error bars. However, I was not able to program the legend to appropriate reflect the two plots.

It only shows Plot 0, while I have two curves on the same plot called AMP and AMP2.

Just like the XY Graph, I tried to get Property Node Plot name, but I didn't see that (and tried other Legend related properties) in the 2D error plot. lik

 

The data coming from my tester has the format (X1, Y1, ERR1), (X2, Y2, ERR2), and so on in separate files. The number of files can vary from 1 to 6 or seven.

 

What I would like is to be able to open the folder that contains these files, select those files that I want to plot, and be able to plot them, and have the plot

display the legend as AMP1, AMP2, AMP3, for cuve 1, curve 2, curve 3, etc. If I choose 4 files, then it should display 4 curves with legend reflecting this fact.

Again, the number can vary. Also, the four curves should have different colors and markers.

 

My idea is to put the files I select in an array, and create a for loop with N = size of this array, and put the "Plot Helper" part of the 2D Error Plot inside this for loop

with a shift register. This will connect the "Plot Helper" portion of the 2D Error Plot in a series and once the loop is finished, all the curves will be shown on the 2D Error Plot

outside of the for loop. I think this should work. The part that I need help with is how to dynamically change the legend. Am I going about this the right way?

 

I assume 2D error plot is not as powerful as XY Graph, but perhaps sufficient for my purpose.

 

 

0 Kudos
Message 6 of 18
(6,467 Views)

I figured this out. After exploring more, the legend can be changed by Create -> Property Node -> Plot Specific -> Error Bar name

0 Kudos
Message 7 of 18
(6,456 Views)

Hi GerdW,

 

I'm close to getting this done, but unfortunately, the legend doesn't automatically increase with the number of plots.

I am plotting two curves, Amp1 and Amp2, by my left says Amp2, then Plot0. Please see the attached VI and the test file I have created.

Thanks!

 

Download All
0 Kudos
Message 8 of 18
(6,451 Views)

Hi murchak,

 

You really are almost there- you just need to update the Active Plot for each iteration of your For Loop.  The end result should look something like this:

 

2D_Error.png

 

 

Jayme W.
Applications Engineer
National Instruments
Message 9 of 18
(6,420 Views)

Hi JaymeW,

 

Thank you for your reply! As much as I like to read and learn more about LabVIEW, I'm very busy with work right now so I know I lack

the fundamentals. How do you get the 2D Error Bar (strict) property shown inside the for loop? What is a "strict?"

0 Kudos
Message 10 of 18
(6,404 Views)