【问题标题】:Custom Color Range with OxyPlot ScatterPlot使用 OxyPlot ScatterPlot 自定义颜色范围
【发布时间】:2017-10-26 18:56:50
【问题描述】:

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

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

以上点颜色是按照教程here创建的。基本上,我添加了 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);

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

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

【问题讨论】:

    标签: c# .net wpf data-visualization oxyplot


    【解决方案1】:

    使用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;
        }
    }
    

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

    axis1.Palette.Colors.Clear();
    
    for (int i = 0; i < 256; i++)
        axis1.Palette.Colors.Add(OxyColor.FromArgb((byte)i, 255, 0, 0));
    

    【讨论】:

    • 嘿 jstreet,是否可以指定 LinearColorAxis 中的值的范围应该是什么颜色。对于您的示例,它在 0 到 2 * PI 之间从蓝色一直过渡到红色。如果我只想从 0 到 2* PI 从浅红色过渡到深红色怎么办
    • 请看我的编辑
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-21
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-01
    相关资源
    最近更新 更多