Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error bars on XYCharts when adding a series with standard deviations

See original GitHub issue

Hi, thanks for your great software.

I’m investigating using XChart, and I’ve come across what I’m guessing is problem in the error bar and display of XY Scatter graphs. It’s not clear to me what the units of the error bars are. I’ve assumed they were one standard deviation.

Regardless of this fact, I have found that the Y values when displayed with error bars are centered at a point approximately equal to the error bar value.

For example, if these values are added to List<Double> yValues and List<Double> errors, then I get the the chart that I have attached.

M = 0.0 SD = 0.0 M = 0.5 SD = 0.11785113019775793 M = 0.3333333333333333 SD = 0.09001028747788695 M = 0.25 SD = 0.07216878364870322 M = 0.2 SD = 0.06106058517348482 M = 0.3333333333333333 SD = 0.05328406170749724

In the Chart, I except that the first few Y values where it is centered to be 0.0, 0.5 and 0.3333333 respectively. This works perfectly without error bars. As soon as I add a set of doubles containing the standard deviation values, the plotted Y values are less, by approximately the standard deviation (see the image attached).

Screenshot from 2020-12-13 11-36-15

If it helps, here is a class I am messing about with to try to get this set up: When “addSeries” is called with the data and standard deviation values, I get the output in the image above.

package xcharttest;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import org.knowm.xchart.XChartPanel;
import org.knowm.xchart.XYChart;
import org.knowm.xchart.XYChartBuilder;
import org.knowm.xchart.XYSeries;
import org.knowm.xchart.XYSeries.XYSeriesRenderStyle;

public class ScatterChartMeanStandardDev
	// Up to six colours for six series
	private static final Color[] COLORS = new Color[] {,,,Color.cyan,,};
	private int currentColorIdx;
	private static final int MAX_COLORS = COLORS.length;
	private XYChart chart;
	public ScatterChartMeanStandardDev(String title,
									   String yLabel,
									   Dimension dimension)
		currentColorIdx = 0;
	    this.chart = setChartStyle(title,
	    							  "Test Number",
	public XYChart setChartStyle(String title, String xLabel, String yLabel, Dimension windowSize) 
		title += " (Error bar = +/- 1 SD)";

		XYChart chart = new XYChartBuilder().width((int)windowSize.getWidth())
	    return chart;
	 * Add a series to the chart as indicated by the parameters
	 * @param seriesName				String label that appears to identify the series line
	 * @param yValues					The Y values of the series (X is assumed to be test number)
	 * @param standardDeviations		The standard deviations ("error" = 68% of normally distributed data)
	 * @return
	public void addSeries(String seriesName,
						  ArrayList<Double> yValues,
						  ArrayList<Double> standardDeviations)
		if (yValues == null || standardDeviations == null) throw new IllegalArgumentException("Data must not be null");
		if (yValues.size() < 1) throw new IllegalArgumentException("No data for chart");
		if (yValues.size() != standardDeviations.size())
			throw new IllegalArgumentException("Y values and standard deviation list sizes should match");
		if (currentColorIdx >= MAX_COLORS)
			throw new IllegalArgumentException("Run out of colors in Scatter Chart addSeries()!");

		List<Double> testNumbers = new LinkedList<>();
	    for (int i = 0; i < yValues.size(); i++) 
	    	testNumbers.add(new Double(i+1));
	    XYSeries series = chart.addSeries(seriesName, testNumbers, yValues, standardDeviations);
	public void swingShow()
	    javax.swing.SwingUtilities.invokeLater(new Runnable() {

	    	  public void run() {

	    	    // Create and set up the window.
	    	    JFrame frame = new JFrame("Test Stats");
	    	    frame.setLayout(new BorderLayout());

	    	    // chart
	    	    JPanel chartPanel = new XChartPanel<XYChart>(chart);
	    	    frame.add(chartPanel, BorderLayout.CENTER);

	    	    // label
	    	    JLabel label = new JLabel("Test Error Bars", SwingConstants.CENTER);
	    	    frame.add(label, BorderLayout.SOUTH);

	    	    // Display the window.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

bluejazzsharkcommented, Dec 29, 2020

Hi Tim,

Many thanks for letting me know. I’ve just tried it out and the error bars work fine now.



On Wed, Dec 23, 2020 at 8:42 AM Tim Molter wrote:

Closed #540

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe .

Antes de juzgar a alguien, primero anda una milla en sus zapatos. Así estás a una milla, y tienes sus zapatos.

timmoltercommented, Dec 23, 2020

FYI, 3.7.0 released.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add, change, or remove error bars in a chart - Microsoft Support
Error bars in charts you create can help you see margins of error and standard deviations at a glance. They can be shown...
Read more >
Excel Standard Deviations and Error Bars for Better Graphs
Data isn't always perfect, absolute and complete. Convey more information in your graphs by adding Excel standard deviations and error bars. Here's how....
Read more >
Adding error bars - Microsoft Excel 2003
Standard Deviation (s): The error bars are in the number of standarddeviation units that you specify. (Excel calculates the standard deviation of the...
Read more >
How to add error bars in Excel: standard and custom - Ablebits
In this example, I'll show you how to make individual standard deviation error bars. To begin with, enter all the error bar values...
Read more >
X/Y Error Bars - LibreOffice Help
When "standard deviation" is selected, x or y is the mean value of the data series. NegativeErrorValue and PositiveErrorValue are the amounts calculated...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found