# 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)
