Recent

Author Topic: Box-and-whisker plot with outliers  (Read 712 times)

apeoperaio

  • Sr. Member
  • ****
  • Posts: 293
Box-and-whisker plot with outliers
« on: October 21, 2025, 04:54:38 pm »
Hi,
Is it possible to add outliers to the box-and-whisker plot? (see https://en.wikipedia.org/wiki/Box_plot).
Outliers are represented as points above and below the whiskers.
Should I use two different series? A TBoxAndWhiskerSeries and a TLineSeries?
There are any example around?
Thank you!

wp

  • Hero Member
  • *****
  • Posts: 13352
Re: Box-and-whisker plot with outliers
« Reply #1 on: October 21, 2025, 07:36:29 pm »
I am afraid that it is not feasible to add outliers to the Box-and-Whisher series in TAChart. This is because in TAChart the chart-source which provides the data to the series must have a well-definded number of x and y values for all data points. In the Box-and-Whisker series there are 1 x value and 5 y values (whisker min, box min, box center, box max, whisker max). Outliers should be included in the same chart source. But since the number of outliers is not the same for all data points the source cannot have a pre-defined count of y values any more.

I'd recommend to put the outliers into a line series in which you turn on the pointer symbols and turn off the connecting lines. Give the outlier series the same color as the related box/whisker series to indicate that they belong together.

See a simple demo in the attachment.

apeoperaio

  • Sr. Member
  • ****
  • Posts: 293
Re: Box-and-whisker plot with outliers
« Reply #2 on: October 22, 2025, 02:56:37 pm »
Thank you for the prompt reply and for the demo. Very useful.

apeoperaio

  • Sr. Member
  • ****
  • Posts: 293
Re: Box-and-whisker plot with outliers
« Reply #3 on: November 13, 2025, 10:54:43 am »
I encountered an unexpected behaviour related on how to add values to the box and whiskers plot.

In the project included in this thread the points are added using the dedicated method:

Code: Pascal  [Select][+][-]
  1.    
  2. ABoxAndWhiskerSeries.AddXY(
  3.       AData[i].Date,
  4.       AData[i].Min,
  5.       AData[i].LowerQuartile,
  6.       AData[i].Median,
  7.       AData[i].UpperQuartile,
  8.       AData[i].Max
  9.     );  
  10.  

The previous code works properly (see image1.png), while the following code does not draw the box and whiskers plot properly (see image2.png):

Code: Pascal  [Select][+][-]
  1.    
  2.     ABoxAndWhiskerSeries.AddXY(AData[i].Date, AData[i].Min);
  3.     ABoxAndWhiskerSeries.AddXY(AData[i].Date, AData[i].LowerQuartile);
  4.     ABoxAndWhiskerSeries.AddXY(AData[i].Date, AData[i].Median);
  5.     ABoxAndWhiskerSeries.AddXY(AData[i].Date, AData[i].UpperQuartile);
  6.     ABoxAndWhiskerSeries.AddXY(AData[i].Date, AData[i].Max);  
  7.  

Why? Aren't the two code snippets equivalent? Am I doing something wrong?


I am using:
Lazarus 4.4 (rev lazarus_4_4) FPC 3.2.2 aarch64-darwin-cocoa

wp

  • Hero Member
  • *****
  • Posts: 13352
Re: Box-and-whisker plot with outliers
« Reply #4 on: November 13, 2025, 12:02:10 pm »
TBoxAndWhiskerSeries is a multi-valued series which requires all y values per data point at once. Doing this in "steps" like you are proposing, adds each time a new data point with the same x value and a single y value.

apeoperaio

  • Sr. Member
  • ****
  • Posts: 293
Re: Box-and-whisker plot with outliers
« Reply #5 on: November 13, 2025, 12:14:39 pm »
Ok, thank you!

 

TinyPortal © 2005-2018