P1D arrays and data manipulations
Code: "p1d_operation1.py". Programming language: Python
DMelt Version 1. Last modified: 12/08/2015. License: Pro
https://datamelt.org/code/cache/p1d_operation1_7957.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.
# S.Chekanov
from java.awt import Color,Font
from java.util import Random
from jhplot import HPlot,P1D
from math import sqrt;
c1 = HPlot("Canvas",600,400,1, 1)
c1.visible(1)
c1.setAutoRange()
c1.setGTitle("Operations with data", Color.blue) #put title
c1.viewHisto(0) # make sure starts from 0
# fill first data set
p1= P1D("data1")
p1.add(10,100,5,5)
p1.add(20,50,5,5)
p1.add(30,80,5,5)
print p1.dimension()
# now add some random numbers
rand = Random()
for i in range(100):
p1.add(10*rand.nextGaussian(), 20*rand.nextGaussian(),0,0)
# make copies of this object
pp1=p1.copy()
pp2=p1.copy()
pp3=p1.copy()
c1.draw(p1)
# now scale the original object in Y
pp1.operScale(1,0.1)
pp1.setTitle("scaled in Y")
pp1.setColor(Color.red)
# now scale in X
pp2.operScale(0,0.1)
pp2.setTitle("scaled in X")
pp2.setColor(Color.green)
# now scale in X
pp3.operSmooth(0,1,4)
pp3.setTitle("smoothed")
pp3.setColor(Color.gray)
c1.draw(pp1)
c1.draw(pp2)
c1.draw(pp3)
You see the box below because you did not login.