public ScatterPlot CreateScatterPlot(string variableNameX, string variableNameY, string variableNameColor = "-") { ScatterPlot scatterPlot = new ScatterPlot(); IList <double> xValues = PreprocessingData.GetValues <double>(PreprocessingData.GetColumnIndex(variableNameX)); IList <double> yValues = PreprocessingData.GetValues <double>(PreprocessingData.GetColumnIndex(variableNameY)); if (variableNameColor == null || variableNameColor == "-") { List <Point2D <double> > points = new List <Point2D <double> >(); for (int i = 0; i < xValues.Count; i++) { Point2D <double> point = new Point2D <double>(xValues[i], yValues[i]); points.Add(point); } ScatterPlotDataRow scdr = new ScatterPlotDataRow(variableNameX + " - " + variableNameY, "", points); scatterPlot.Rows.Add(scdr); } else { var colorValues = PreprocessingData.GetValues <double>(PreprocessingData.GetColumnIndex(variableNameColor)); var data = xValues.Zip(yValues, (x, y) => new { x, y }).Zip(colorValues, (v, c) => new { v.x, v.y, c }).ToList(); var gradients = ColorGradient.Colors; int curGradient = 0; int numColors = colorValues.Distinct().Count(); foreach (var colorValue in colorValues.Distinct()) { var values = data.Where(x => x.c == colorValue); var row = new ScatterPlotDataRow( variableNameX + " - " + variableNameY + " (" + colorValue + ")", "", values.Select(v => new Point2D <double>(v.x, v.y)), new ScatterPlotDataRowVisualProperties() { Color = gradients[curGradient] }); curGradient += gradients.Count / numColors; scatterPlot.Rows.Add(row); } } return(scatterPlot); }
public ScatterPlot CreateScatterPlot(string variableNameX, string variableNameY) { ScatterPlot scatterPlot = new ScatterPlot(); IList <double> xValues = PreprocessingData.GetValues <double>(PreprocessingData.GetColumnIndex(variableNameX)); IList <double> yValues = PreprocessingData.GetValues <double>(PreprocessingData.GetColumnIndex(variableNameY)); List <Point2D <double> > points = new List <Point2D <double> >(); for (int i = 0; i < xValues.Count; i++) { Point2D <double> point = new Point2D <double>(xValues[i], yValues[i]); points.Add(point); } ScatterPlotDataRow scdr = new ScatterPlotDataRow(variableNameX + " - " + variableNameY, "", points); scatterPlot.Rows.Add(scdr); return(scatterPlot); }