我正在尝试为我的数据绘制趋势线。无论如何要定义一个自定义函数?我见过的最接近的是此处的 Hello Windows Forms 示例中的 with:http://www.oxyplot.org/doc/HelloWindowsForms.html
代码:
namespace WindowsFormsApplication1
{
using System;
using System.Windows.Forms;
using OxyPlot;
using OxyPlot.Series;
public partial class Form1 : Form
{
public Form1()
{
this.InitializeComponent();
var myModel = new PlotModel("Example 1");
myModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)"));
this.plot1.Model = myModel;
}
}
}
在示例中,他们使用余弦。如果我需要定义自定义多变量方程怎么办?
编辑: 我找到了部分答案。
使用 Lambda 系列:
new FunctionSeries( x => a*x*x*x + b*x*x + c*x + d, .... )
来源: https://oxyplot.codeplex.com/discussions/439064
虽然仍然不知道如何计算多变量方程。
最佳答案
示例图片如下: 这是代码:
//your function based on x,y
public double getValue(int x, int y)
{
return (10 * x * x + 11 * x*y*y + 12*x*y );
}
//setting the values to the function
public FunctionSeries GetFunction()
{
int n = 100;
FunctionSeries serie = new FunctionSeries();
for (int x = 0; x < n; x++)
{
for (int y = 0; y < n; y++)
{
//adding the points based x,y
DataPoint data = new DataPoint(x, getValue(x,y));
//adding the point to the serie
serie.Points.Add(data);
}
}
//returning the serie
return serie;
}
//setting all the parameters of the model
public void graph()
{
model = new PlotModel { Title = "example" };
model.LegendPosition = LegendPosition.RightBottom;
model.LegendPlacement = LegendPlacement.Outside;
model.LegendOrientation = LegendOrientation.Horizontal;
model.Series.Add(GetFunction());
var Yaxis = new OxyPlot.Axes.LinearAxis();
OxyPlot.Axes.LinearAxis XAxis = new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Bottom, Minimum = 0, Maximum = 100 };
XAxis.Title = "X";
Yaxis.Title = "10 * x * x + 11 * x*y*y + 12*x*y";
model.Axes.Add(Yaxis);
model.Axes.Add(XAxis);
this.plot.Model = model;
}
//on click on the button 3 then show the graph
private void button3_Click(object sender, EventArgs e)
{
graph();
}
关于c# - 如何在 OxyPlot 中绘制自定义函数的图形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25313258/