 |
Loess (Lowess) smoothing of a histogram
Source code name: "stat_smoothing.py"
Programming language: Python
Topic: Statistics/Smoothing
DMelt Version 1. Last modified: 12/25/2015. License: Pro
https://datamelt.org/code/cache/stat_smoothing_5459.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
# Here we use weightied smoothing as given by a Gaussian-like histogram
from java.awt import Color,Font
from java.util import Random
from jhplot import HPlot,H1D
from jhplot.stat import Interpolator
c1 = HPlot("Canvas",600,400)
c1.setGTitle("Title")
c1.visible()
c1.setRange(-2,3,0,100)
h2 = H1D("Background",50, -2.0, 3.0)
h2.setFill(1)
h2.setErrX(0)
h2.setErrY(1)
h2.setFillColor(Color.red)
h2.setColor(Color.red)
h2.setErrColorY(Color.blue)
r=Random()
for i in range(1000):
h2.fill(r.nextGaussian()-2)
if (i<500): h2.fill(r.nextGaussian()*0.4+1)
c1.draw(h2)
k=Interpolator(h2)
p1=k.smoothLoess(0.2,0,0.4)
p1.setStyle("l")
c1.draw(p1)
You see the box below because you did not login.