Tutorial:DataMelt/3 Data Containers

From HandWiki

1D arrays

1D arrays in DataMelt are designed for numerical calculations and are optimized for numbers. We first consider P0D P0D arrays (to hold double values) and P0I P0I (to hold integer values)

<jc lang="dmelt"> from jhplot import P0D p0=P0D("test") for i in range(10):

     p0.add(i)

print p0.toString() </jc>

One can view the data containers using several methods. One is toString() which converts data into a string. One can write data into a file (including a compression) using the method toFile(file). One can also view data in a sortable table using the method toTable():

<jc lang="dmelt"> from jhplot import P0D p0=P0D("test") for i in range(1,50,2):

     p0.add(i)

p0.toTable() </jc>

As for any DataMelt data object, one can write and read arrays into files using the method "toFile" and read using the method "read()"

p0.toFile("data.txt")

and read it back as:

p0.read("data.txt")

If a file was zipped use the method "readZip()".

One can access various statistical characteristics of the P0D arrays as:

<jc dmelt member_edit> from jhplot import P0D p0=P0D("test") for i in range(1,50,2):

     p0.add(i)

print p0.getStatString() </jc> <fc #008000>Exercise: try to increase the number of iteration to 1000 and see the output. </jnote>


jhplot classes


colt classes

2D arrays

2D arrays are based on the Java class P1D P1D. This class can be used to show data in X-Y plane As before, one can fill such arrays using the method "add(x,y)".

Here is a simple example how to show several data sets on on X-Y graph: <jc lang="dmelt"> from jhplot import P1D, HPlot from java.awt import Color

p1=P1D("1st data set") p1.add(1,2); p1.add(2,3); p1.add(4,5)

p2=P1D("2nd data set") p2.add(-1,3); p2.add(5,-2); p2.add(1,0) p2.setColor(Color.red)

c1 = HPlot("Canvas") c1.visible() c1.setAutoRange() c1.draw(p1); c1.draw(p2) </jc>

jhplot classes

[[/dmelt/api/jhplot/P1D.html|jhplot.P1D</javadoc> - double X-Y values (errors optionally) [[/dmelt/api/jhplot/math/DoubleArray.html|jhplot.math.DoubleArray</javadoc> - double X-Y values [[/dmelt/api/jhplot/math/IntegerArray.html|jhplot.math.IntegerArray</javadoc> - integer X-Y values

N-dimensional arrays

<ifauth ns="learn">

jhplot classes