2017-05-26 338 views
2

我一直在實驗與我的系列的頂部oxyplot散點圖的實驗。基本上,我喜歡在散點圖上對代碼進行顏色編碼。自定義顏色範圍與OxyPlot ScatterPlot

我已經有下面的散點圖和線系列創建的圖形:創建下面的教程here

enter image description here

上述點的顏色。基本上,我添加了一個RangeColorAxis。從0到1和x軸從該曲線範圍創建的顏色,如以下:

 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中做到這一點?由於

回答

2

使用LinearColorAxis

enter image description here

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

編輯:您還可以定義自己的調色板:

enter image description here

axis1.Palette.Colors.Clear(); 

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

Hey jstreet,是否可以指定RangeColorAxis中值的範圍。對於您的示例,它在0到2 * PI之間從藍色轉變爲紅色。如果我只想從淺紅色轉換爲深紅色從0到2 * PI – Mantracker

+0

請參閱我的**編輯**。 – jsanalytics