C#Oxyplot水平箱图

时间:2018-03-04 16:45:53

标签: c# wpf oxyplot

我在Oxyplot中创建了一系列的箱形图,看起来像 this
是否可以将它们绘制为水平框图,因此它们看起来更像this
我的代码如下:

 var plot = new PlotModel();
        var items = new Collection<Item>();

        foreach (var item in MainWindow.classificationDistances)
        {
            items.Add(new Item { Label = item.Key.ToString() });
        }

        plot.Axes.Add(new LinearAxis
        {
            Position = AxisPosition.Left,
            MajorStep = 0.025,
            MinorStep = 0.005,
            Key = "Distance",
            TickStyle = TickStyle.Crossing,
            AbsoluteMaximum = 1,
            AbsoluteMinimum = -0.25
        });

        plot.Axes.Add(new CategoryAxis
        {
            Position = AxisPosition.Bottom,
            ItemsSource = items,
            LabelField = "Label",                 
            Key = "Classification",
            IsTickCentered = true,
            TickStyle = TickStyle.None,
            IsZoomEnabled = false
        });


        var s1 = new BoxPlotSeries
        {
            Fill = OxyColor.FromRgb(0x1e, 0xb4, 0xda),
            StrokeThickness = 1.1,
            WhiskerWidth = 1
        };

        double x = 0;
        foreach (var item in MainWindow.classificationDistances)
        {                
            var values = new List<double>();
            foreach (var value in item.Value)
            {
                values.Add(value);
            }

            values.Sort();
            var median = getMedian(values);
            int r = values.Count % 2;
            double firstQuartil = getMedian(values.Take((values.Count + r) / 2)); // 25%-Quartil
            double thirdQuartil = getMedian(values.Skip((values.Count - r) / 2)); // 75%-Quartil

            var iqr = thirdQuartil - firstQuartil; // Quartilabstand
            var step = 1.5 * iqr;
            var upperWhisker = thirdQuartil + step;
            upperWhisker = values.Where(v => v <= upperWhisker).Max();
            var lowerWhisker = firstQuartil - step;
            lowerWhisker = values.Where(v => v >= lowerWhisker).Min();
            var outliers = values.Where(v => v > upperWhisker || v < lowerWhisker).ToList();

            s1.Items.Add(new BoxPlotItem(x, lowerWhisker, firstQuartil, median, thirdQuartil, upperWhisker));
            x++;
        }

        plot.Series.Add(s1);
        return plot;

交换线性和类别轴位置确实会适当地改变轴,但数据为completely unreadable

此外,是否可以绘制概率密度,因此我最终可能会得到类似this?

的内容。

非常感谢任何帮助。

0 个答案:

没有答案