- 网址收藏 → 我可以帮你整理一个程序员/开发/资料类的网址收藏清单,方便你查找学习。
- OxyPlot 正态分布图 → 用 C# 调用 OxyPlot 绘制标准正态分布(高斯曲线)的示例代码。
① 网址收藏(精选实用开发工具站)
分类 | 网站名称 | 地址 | 用途 |
---|---|---|---|
文档 & API | MDN Web Docs | https://developer.mozilla.org/ | Web 前端/JavaScript 官方参考 |
文档 & API | DevDocs | https://devdocs.io/ | 集成多种编程语言/API 文档 |
在线编译 | Repl.it | https://repl.it/ | 在线运行多种语言代码 |
代码托管 | GitHub | https://github.com/ | 代码版本管理与协作 |
代码托管 | Gitee(码云) | https://gitee.com/ | 国内代码托管平台 |
数据可视化 | ECharts | https://echarts.apache.org/ | 前端可视化图表库 |
C# 图表 | OxyPlot | https://oxyplot.readthedocs.io/ | .NET 图表绘制库 |
工具 | JSON Editor Online | https://jsoneditoronline.org/ | JSON 数据可视化编辑 |
工具 | Regex101 | https://regex101.com/ | 正则表达式测试 |
学习 | LeetCode | https://leetcode.com/ | 算法与数据结构刷题 |
学习 | W3Schools | https://www.w3schools.com/ | 前端/后端基础教程 |
学习 | 菜鸟教程 | https://www.runoob.com/ | 全栈入门教程 |
学习 | 阮一峰的网络日志 | https://ruanyifeng.com/blog/ | 技术文章与教程 |
PDF 工具 | SmallPDF | https://smallpdf.com/ | 在线 PDF 编辑、转换 |
② OxyPlot 绘制正态分布图(C#)
下面的例子用 C# + OxyPlot 绘制一条标准正态分布曲线(μ=0, σ=1)。
using OxyPlot;
using OxyPlot.Series;
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
var model = new PlotModel { Title = "正态分布曲线" };
var series = new LineSeries
{
Title = "N(0,1)",
StrokeThickness = 2
};
double mean = 0.0; // μ
double stdDev = 1.0; // σ
int points = 200; // 数据点数量
double step = 0.1;
for (double x = -4; x <= 4; x += step)
{
double y = (1 / (stdDev * Math.Sqrt(2 * Math.PI))) *
Math.Exp(-0.5 * Math.Pow((x - mean) / stdDev, 2));
series.Points.Add(new DataPoint(x, y));
}
model.Series.Add(series);
// 导出为图片
var pngExporter = new OxyPlot.SkiaSharp.PngExporter { Width = 600, Height = 400 };
using (var stream = System.IO.File.Create("normal_distribution.png"))
{
pngExporter.Export(model, stream);
}
Console.WriteLine("正态分布图已生成:normal_distribution.png");
}
}
说明:
- 使用
LineSeries
绘制曲线。 - 公式是标准正态分布概率密度函数: f(x)=1σ2πe−(x−μ)22σ2f(x) = \frac{1}{\sigma\sqrt{2\pi}} e^{ -\frac{(x-\mu)^2}{2\sigma^2} }
- 最终会生成一个 PNG 图片文件。
发表回复