Tutorial:DataMelt/4 Plots

From HandWiki

2D plots

Typically, you can build a canvas like this:

from jhplot import HPlot
c1 = HPlot("Canvas",600,400,2,1) # canvas size 600x400, 2 plot regions
c1.visible(49,50)    # show it on the screen at position 40,50
c1.setAutoRange()    # autorange for X
c1.draw(object1)     # draw object1 (H1D,F1D,P1D etc)
c1.draw(object2)     # draw a new object
c1.export("figure.pdf") # export to PDF file

This code create a canvas with the size 600x400 (in pixels), it has 2 pads to show data. The method visible(100,200) make the canvas visible and sets its location on the screen at position 100 (in X from left conner) and 200 (from top) in pixels. If you want a default position, jut call "visible()". Then you can draw any mathematical object or data. Then you can export the image to vector format. Now you are ready to plot functions, histograms and datasets. See the detail in jhplot.HPlot jhplot.HPlot

Let's run this code and make an empty canvas with 2 plot regions:

<jc lang="dmelt"> from jhplot import HPlot c1 = HPlot("Canvas",600,400,2,1) # canvas size 600x400, 2 plot regions c1.visible() # make it visible </jc>

Let us draw a function on this canvas using the default attributes for the canvas:

<jc lang="dmelt"> from jhplot import HPlot,F1D c1 = HPlot("Canvas") c1.visible() c1.setAutoRange() f=F1D('sin(x)*x',-10,10) # range -10 - 10 c1.draw(f) </jc>

Read DataMelt documentation for detailed description.

3D plots

Typically, you can build a canvas in 3D (X-Y-Z) as:

from jhplot import HPlot3D
c1 = HPlot3D("Canvas",600,400,2,1) # canvas size 600x400, 2 plot regions
c1.visible(10,20)  # make it visible and position at 10-20 pixels 
c1.setAutoRange()    # autorange for X
c1.draw(object1)     # draw object1 (H2D,F2D,P2D etc)
c1.draw(object2)     # draw a new object
c1.export("figure.pdf") # export to PDF file

This code create a canvas with the size 600x400 (in pixels), it has 2 pads to show data. The method visible(100,200) make the canvas visible and sets its location on the screen at position 100 (in X from left conner) and 200 (from top) in pixels. If you want a default position, jut call "visible()". Then you can draw any mathematical object or data. Then you can export the image to vector format. Now you are ready to plot functions, histograms and datasets. See the detail in jhplot.HPlot3D jhplot.HPlot3D

Let us build a canvas without any data:

<jc lang="dmelt"> from jhplot import HPlot3D c1 = HPlot3D("Canvas",600,400,2,1) # canvas size 600x400, 2 plot regions c1.visible() # make it visible screen </jc>

Let us show a simple example by plotting a function of 2 variables in X and Y in this 3D canvas:

<jc lang="dmelt"> from jhplot import HPlot3D,F2D c1 = HPlot3D("Canvas") c1.visible() f=F2D('0.2*x*y*cos(x)*sin(y)',-10,10,-10,10) c1.draw(f) </jc>