【问题标题】:How do I graph a custom function in OxyPlot?如何在 OxyPlot 中绘制自定义函数?
【发布时间】:2014-08-14 16:40:31
【问题描述】:

我正在尝试为我的数据绘制趋势线。反正有定义自定义函数吗?我见过的最接近的是这里的 Hello Windows Forms 示例: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

但仍然不知道如何做一个多变量方程。

【问题讨论】:

    标签: c# windows winforms plot oxyplot


    【解决方案1】:

    以下是示例图片: 这是代码:

        //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();
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-07
      • 1970-01-01
      • 1970-01-01
      • 2022-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多