LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error bar in XY Graph

Hello members,

 

I am wondering how I could use error bar in my XY graph. I read a couple of very old posts regarding the error bar plots, but I could not find those or related properties in XY graph. Was it removed or any advanced features came up in the newer version?

 

If anyone has recently used error bars, kindly let me know where I can find it and how to use it.

Thanks,

Pradeep.

0 Kudos
Message 1 of 11
(1,803 Views)

What is an "Error Bar"?  If I have a point P at a coordinate (x, y), one way to plot an "error bar" showing ±e at the point P is to draw a line from (x, y+e) to (x, y-e).  If you want to be fancy, and put little "hats" of width "h" at the top and bottom of the error bar, that's two more lines, from (x-h, y+e) to (x+h, y+e) and (x-h, y-e) to (x+h, y-e).

 

What a pain!  No, not really -- simply write a sub-VI called "Error Bar" with three Inputs:  the Array of Points [P], another Array of Errors [E], and a "hat width" (h).  Inside, you have a For loop that does the above calculations and draws the Error Bars on the Graph.

 

Oops, "on the Graph" -- you need one more input, a reference to the Graph.  To keep your sub-VI "neat", I recommend using the standard 4-2-2-4 Connector Pane, with Error In and Error Out on the lower corners, P, E, and h on the left edge, and the Graph Reference on the top left input.

 

Have fun.  It shouldn't take you very long to create this sub-VI.  Oh, definitely do make it a sub-VI, if for no other reason than you might want to put Error Bars on more than one Graph, or may want to do this again a month from now ...

 

Bob Schor

0 Kudos
Message 2 of 11
(1,780 Views)

Hi Bob Schor,

 

Thank you for the immediate reply. You sounded very easy and I hope it is. Although I did not understand the 3rd paragraph '4-2-2-4', I will give it a good try. Many thanks.

 

Pradeep.



 

0 Kudos
Message 3 of 11
(1,772 Views)

Pradeep,

 

     My apologies for being obscure.  Here is the explanation:  When you create a new VI (for example, by typing ^N), you get a blank Front panel, and in the upper right-hand corner, a "Generic NI Icon" and the Default Connector Pane, a square with four smaller squares on the left edge, followed by two 1x2 rectangles, two more 1x2 rectangles, and four more 1x1 squares.  This is the "4-2-2-4" Connector Pane, which I use for almost 100% of the VIs and sub-VIs I create (even those that only have Error In and Error Out).  Indeed, there is a good argument to be made for using no more than 1 or 2 Inputs (not counting Error In) and a similar small number of outputs (not counting Error Out) in most of the VIs that you write.  [Don't get me started on notions of LabVIEW "Style" ...].

 

Bob Schor

0 Kudos
Message 4 of 11
(1,757 Views)

@Bob_Schor wrote:

What is an "Error Bar"?  If I have a point P at a coordinate (x, y), one way to plot an "error bar" showing ±e at the point P is to draw a line from (x, y+e) to (x, y-e).  If you want to be fancy, and put little "hats" of width "h" at the top and bottom of the error bar, that's two more lines, from (x-h, y+e) to (x+h, y+e) and (x-h, y-e) to (x+h, y-e).

 

What a pain!  No, not really -- simply write a sub-VI called "Error Bar" with three Inputs:  the Array of Points [P], another Array of Errors [E], and a "hat width" (h).  Inside, you have a For loop that does the above calculations and draws the Error Bars on the Graph.

 

Oops, "on the Graph" -- you need one more input, a reference to the Graph.  To keep your sub-VI "neat", I recommend using the standard 4-2-2-4 Connector Pane, with Error In and Error Out on the lower corners, P, E, and h on the left edge, and the Graph Reference on the top left input.

 

Have fun.  It shouldn't take you very long to create this sub-VI.  Oh, definitely do make it a sub-VI, if for no other reason than you might want to put Error Bars on more than one Graph, or may want to do this again a month from now ...

 

Bob Schor


reminds me of this:

 

https://forums.ni.com/t5/Example-Code/Creating-Boxplots-Using-LabVIEW/ta-p/3534434?profile.language=...

0 Kudos
Message 5 of 11
(1,736 Views)

Error bar...?  Limit lines?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 11
(1,727 Views)

I was a bit curious as to how 'easy' this actually was, so I put together a VI to generate a second plot from a first plot using the Complex Double datatype as the input.

This has some nice advantages in allowing potentially error bars with X too, but I didn't implement that here (the errors are just Double values).

 

To allow multiple plots, you'd need to change the input datatype, or perhaps just run this VI inside a For loop and concatenate the outputs.

The VIs are saved for 2019.

cbutcher_0-1627879790544.png

 

cbutcher_1-1627879815829.png

cbutcher_2-1627879833366.png

 

 

 

Pradeep, the key points here (you may already know this, but I'll write anyway) are

  • The Complex Double datatype combines two values, which the XY Graph can use as X and Y values. So the Real component gives the X value and the Imaginary the Y.
  • NaN on graphs breaks the line. Here I use that between the error bars, so that they don't join up. I also used it for the hats on the error bars (see the case structure in the loop in the first image), but you could instead probably use a different collection of points if you wanted (e.g. TopLeft, TopRight, TopMiddle, BottomMiddle, BottomLeft, BottomRight, NaN or something). That would save you 2 points per data point, but would draw over itself, I don't know the underlying performance tradeoffs. I suspect you shouldn't care, but maybe try both if you have lots and lots and lots of data points and want to plot quickly (but then you probably should decimate, etc, since this won't show much if you have too many points, just lots of blur).

 

 


GCentral
Message 7 of 11
(1,716 Views)

Hi all,

 

Thank you for your feedback.

 

I feel it is over complicated. I already have data that is acquired from different instruments. The array is of 3 columns. [Xdata Ydata Yerr]. I don't need hat width, Xerr, pos/neg error. The columns are of absolutely the same array size. The data is attached. As and when the data points are generated, I would be plotting it in XY graph using shift register.

 

I can make X, Y, E, Y+E, Y-E and plot (X,Y) represented by 'x', (X,Y+E) represented by '-', and (X,Y-E) represented by '-'. The XY plot can be connected with a colored line, while the other two can be connected with transparent line. I may only need to connect the (X,Y+E) with the corresponding (X,Y-E). Is this possible?

 

Thank you.

Pradeep.

0 Kudos
Message 8 of 11
(1,558 Views)

If I understand what you are saying, you are making some simplifying modifications of what CButchter and I both suggested.  You are using "symmetric" Error Bars (so the bar goes up the same amount as it goes down, drawn as a line, which is what I think you mean by "-") and plotting the central data point (second column) as a symbol (which you call "x").  Give it a go, it is quite straight-forward.

 

Something you might find simplifies things is to do the plot in two passes.

  • Pass 1 -- do an XY Plot of Column 2 against Column 1, using whatever connecting Line style and Point style (and color, size, etc.) you prefer.
  • Pass 2 -- add the double-sided Error Bars by drawing Vertical lines from (x, y+err) to (x, y-err) for all sets of points.
  • Don't forget to label the Axes.

Bob Schor

0 Kudos
Message 9 of 11
(1,548 Views)

Hi Bob_Schor,

 

I wanted to use "-" minus/hypen sign for symbol in Error bar points, while "x" sign for central data point. While I could find "x" sign, I could not find "-" sign in the XY graph properties. Is it possible to have "-" sign or any other sign that is not listed in the properties?

 

My next question is, I don't know how to draw vertical lines from (x,y+e) to (x,y-e). Please let me know.

 

Thank you.

Pradeep.

0 Kudos
Message 10 of 11
(1,536 Views)