使用 OxyPlot ScatterPlot 自定义颜色范围

Man*_*ker 4 .net c# wpf data-visualization oxyplot

我一直在尝试在我的线系列之上使用 oxyplot 实现散点图。基本上,我想对散点图上的一些点进行颜色编码。

我已经使用散点图和线系列创建了下面的图表:

在此输入图像描述

上述点颜色是按照此处的教程创建的。基本上,我添加了一个 RangeColorAxis。该图的 X 轴范围从 0 到 1,并创建颜色,如下所示:

        var customAxis = new RangeColorAxis { Key = "customColors" };
        customAxis.AddRange(0, 0.1, OxyColors.Red);
        customAxis.AddRange(0.1, 0.2, OxyColors.Yellow);
        customAxis.AddRange(0.2, 0.3, OxyColors.Green);
        customAxis.AddRange(0.3, 1, OxyColors.Orange);
        customAxis.AddRange(1, 1.1, OxyColors.Blue);
        OxyPlotModel.Axes.Add(customAxis);
Run Code Online (Sandbox Code Playgroud)

但现在,我还想在上图中添加一些颜色渐变。例如,从点 0.0 到 0.1,我希望颜色从浅红色进展到深红色。从 0.1 到 0.2,我想从浅黄色过渡到亮黄色。从0.2到0.3,我想从浅绿色过渡到深绿色。等等。

在 Oxyplot 中可以做到这一点吗?谢谢

jsa*_*ics 5

使用LinearColorAxis

在此输入图像描述

public partial class MainWindow : Window
{
    public PlotModel Model { get; set; }

    public MainWindow()
    {
        InitializeComponent();

        Model = new PlotModel();

        var axis1 = new LinearColorAxis();
        axis1.Key = "ColorAxis";
        axis1.Maximum = 2 * Math.PI;
        axis1.Minimum = 0;
        axis1.Position = AxisPosition.Top;
        Model.Axes.Add(axis1);

        var s1 = new ScatterSeries();
        s1.ColorAxisKey = "ColorAxis";
        s1.MarkerSize = 8;
        s1.MarkerType = MarkerType.Circle;

        for (double x = 0; x <= 2 * Math.PI; x += 0.1)
            s1.Points.Add(new ScatterPoint(x, Math.Sin(x), double.NaN, x));

        Model.Series.Add(s1);

        DataContext = this;
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:您还可以定义自己的调色板:

在此输入图像描述

axis1.Palette.Colors.Clear();

for (int i = 0; i < 256; i++)
    axis1.Palette.Colors.Add(OxyColor.FromArgb((byte)i, 255, 0, 0));
Run Code Online (Sandbox Code Playgroud)