private void DrawDistribution(Dictionary <int, int> dic, Brush brush) { GaussianFit fit = new GaussianFit(); foreach (int key in dic.Keys) { if (dic[key] != 0) { fit.AddPoint(key, dic[key]); } } fit.Solve(); int maxY = dic.Values.Max(); int minX = dic.Keys.Min(); int maxX = dic.Keys.Max(); int x0 = 10; int y0 = 10; float scaleX = (pictureBox.Width - 2 * x0) * 1.0f / (maxX - minX); float scaleY = (pictureBox.Height - 2 * y0) * 1.0f / maxY; if (maxY != 0 && maxX != minX) { using (Graphics g = Graphics.FromImage(pictureBox.Image)) { g.Clear(m_BackgroundColor); float halfBarWidth = (pictureBox.Width - 2 * x0) / (2.0f * dic.Keys.Count); foreach (int x in dic.Keys) { int y = dic[x]; float xx = x0 + (x - minX) * scaleX; float yy = pictureBox.Height - y0 - y * scaleY; g.FillRectangle(brush, xx - halfBarWidth, yy + 1, 2 * halfBarWidth, pictureBox.Height - y0 - yy); } g.Save(); } } pictureBox.Refresh(); }