怎样绘制平滑/圆角/曲线图? (C#) [英] How can I draw smoothed/rounded/curved line graphs? (C#)

查看:301
本文介绍了怎样绘制平滑/圆角/曲线图? (C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我测量了一些系统的性能数据,将其存储在数据库中。从这些数据点,我在一段时间绘制的曲线图。在他们的本性,这些数据点是有点吵,即得。每一个点至少偏离当地的平均值一点。当从一个点直线绘制线图到下一个,它产生锯齿状图形。在一个大的时间尺度上每个像素的像> 10个数据点,这种噪音被压缩成是,比如说广锯齿线区域,20像素,而不是高1px的,因为在较小的规模。

I'm measuring some system performance data to store it in a database. From those data points I'm drawing line graphs over time. In their nature, those data points are a bit noisy, ie. every single point deviates at least a bit from the local mean value. When drawing the line graph straight from one point to the next, it produces jagged graphs. At a large time scale like > 10 data points per pixel, this noise is compressed into a wide jagged line area that is, say, 20px high instead of 1px as in smaller scales.

我读过有关线平滑,抗锯齿,简化了这些东西。但是,一切都我发现好像是别的东西。

I've read about line smoothing, anti-aliasing, simplifying and all these things. But everything I've found seems to be about something else.

我不需要抗锯齿,.NET已经这样做了,我吸取了线的时候屏幕。

I don't need anti-aliasing, .NET already does that for me when drawing the line on the screen.

我不希望简化。我需要的极端值保持可见,至少其中的大多数。

I don't want simplification. I need the extreme values to remain visible, at least most of them.

我认为它会在样条曲线的方向,但我找不到太多的例子图像评估所描述的事情是我想要的。我发现在谷歌图书高度科学的书,虽然,全半页长的公式,我是不喜欢现在通过阅读...

I think it goes in the direction of spline curves but I couldn't find much example images to evaluate whether the described thing is what I want. I did find a highly scientific book at Google Books though, full of half-page long formulas, which I wasn't like reading through now...

要给你一个例子,只要看看Linux的/ GNOME的系统监视器应用程序。我绘制与平滑线最近的CPU /内存/网络使用情况。这可能是过于简单,但我想给它一个尝试,看看我是否能调整它。

To give you an example, just look at Linux/Gnome's system monitor application. I draws the recent CPU/memory/network usage with a smoothed line. This may be a bit oversimplified, but I'd give it a try and see if I can tweak it.

我更喜欢的C#代码,但算法或代码等语言是罚款,也一样,只要我能移植到C#无需外部引用。

I'd prefer C# code but algorithms or code in other languages is fine, too, as long as I can port it to C# without external references.

推荐答案

您可以做一些数据 - 平滑。而不是使用真实数据,应用,保持像Savitzky-Golayfilter峰一个简单的平滑算法

You can do some data-smoothing. Instead of using the real data, apply a simple smoothing algorithm that keeps the peaks like a Savitzky-Golayfilter.

你可以得到的系数这里

最容易做的是:

从网站我联系就拿顶系数:

Take the top coefficients from the website I linked to:

// For np = 5 = 5 data points
var h = 35.0;
var coeff = new float[] { 17, 12, -3 }; // coefficients from the site
var easyCoeff = new float[] {-3, 12, 17, 12, -3}; // Its symmetrical
var center = 2; // = the center of the easyCoeff array



//现在从数据中每一点你计算平滑点:

// now for every point from your data you calculate a smoothed point:

smoothed[x] = 
   ((data[x - 2] * easyCoeff[center - 2]) +
    (data[x - 1] * easyCoeff[center - 1]) +
    (data[x - 0] * easyCoeff[center - 0]) +
    (data[x + 1] * easyCoeff[center + 1]) +
    (data[x + 2] * easyCoeff[center + 2])) / h;



第2和最后2分以5点的时候,你cannoth顺畅。

The first 2 and last 2 points you cannoth smooth when using 5 points.

如果您希望自己的数据更平滑,你可以用较大的数据点的系数的试验。

If you want your data to be more "smoothed" you can experiment with coefficents with larger data points.

现在可以得出一个通过您的平滑数据线。点的较大的NP =数字,平滑数据。但你也松峰的准确性,但没有那么多的时候只是一些点均在一起。

Now you can draw a line through your "smoothed" data. The larger your np = number of points, the smoother your data. But you also loose peak accuracy, but not as much when simply averaging some points together.

这篇关于怎样绘制平滑/圆角/曲线图? (C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆