> 文档中心 > WPF 入门教程ScottPlot使用

WPF 入门教程ScottPlot使用

ScottPlot是一个免费的开源交互式绘图库,适用于 .NET。它具有适用于 Windows 窗体、WPF、Avalonia 和 Eto 窗体的用户控件,它甚至可以在服务器环境或控制台应用程序中将绘图生成为图像文件。ScottPlot 面向 .NET Standard 2.0,因此它可以在 .NET Framework 和 .NET Core 应用程序中使用。ScottPlot 的 API 模仿Python 的Matplotlib,大多数绘图都可以用一行代码创建(使用可选参数来自定义样式)。

交互式控件

  • 左键拖动:平移
  • 右键单击拖动:缩放
  • 中键拖动:缩放区域
  • 滚轮:缩放
  • 中键:拟合数据
  • 右键单击:部署菜单

ScottPlot 图表控件预览

ScottPlot Cookbook是与用于创建它们的源代码配对的样本图的广泛集合。查看图表控件是调查 ScottPlot 功能并学习如何使用它的最佳方式。ScottPlot 演示应用程序中提供了每个图表的交互式版本。

快速入门(控制台)

  • 安装ScottPlot.WinFormsNuGet 包
  • 将以下内容添加到您的启动序列中
double[] dataX = new double[] { 1, 2, 3, 4, 5 };double[] dataY = new double[] { 1, 4, 9, 16, 25 };var plt = new ScottPlot.Plot(400, 300);plt.AddScatter(dataX, dataY);plt.SaveFig("quickstart.png");

快速入门(Windows 窗体)

  • 使用NuGet安装ScottPlot.WinForms包
  • FormsPlot工具箱中的 a 拖到表单上
  • 将以下内容添加到您的启动序列中
// generate some random X/Y dataint pointCount = 500;Random rand = new Random(0);double[] xs1 = ScottPlot.DataGen.RandomWalk(rand, pointCount);double[] ys1 = ScottPlot.DataGen.RandomWalk(rand, pointCount);double[] xs2 = ScottPlot.DataGen.RandomWalk(rand, pointCount);double[] ys2 = ScottPlot.DataGen.RandomWalk(rand, pointCount);// plot the dataformsPlot1.Plot.PlotScatter(xs1, ys1);formsPlot1.Plot.PlotScatter(xs2, ys2);// additional stylingformsPlot1.Plot.Title($"Scatter Plot ({pointCount} points per group)");formsPlot1.Plot.XLabel("Horizontal Axis Label");formsPlot1.Plot.YLabel("Vertical Axis Label");formsPlot1.Refresh();

组词