DScience:3D representation of data

From HandWiki
Revision as of 17:00, 24 December 2019 by imported>Jworkorg
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Member


30% complete
   


3D plots use 3D computer graphics to represent scientific data. Data are usually defined as [math]\displaystyle{ Z=f(X,Y) }[/math], where [math]\displaystyle{ (X,Y,Z) }[/math] values by a function or actual data. There are a number of possible types of 3D plots. You can use the following Java classes to plot data in 3D: jhplot.HPlot3D jhplot.HPlot3D, jhplot.HPlotXYZ jhplot.HPlotXYZ, jhplot.HPlot3DP jhplot.HPlot3DP, jhplot.HVisAd jhplot.HVisAd, jhplot.HPlotMX jhplot.HPlotMX. See additional details in DMelt:Plots/5_Plots_in_3D.


Bar plots or histograms

A bar plot draws a three-dimensional bar chart, where each element in Z corresponds to one bar. To make such plots from a 3D histogram use the Java class jhplot.H2D jhplot.H2D. Here is the Python code with an example:

DMelt example: Showing a 2D histogram in 3D

from jhplot  import HPlot3D,SHPlot3D,H2D
from java.util import Random


# build a standard canvas
c1 = HPlot3D("Canvas",600,400)

# build a singleton
# c1=SHPlot3D.getCanvas()

c1.setGTitle("Global title")
c1.setNameX("Xaxis")
c1.setNameY("Yaxis")
c1.visible(1)

h1 = H2D("My 2D Test",20,-3.0, 3.0, 20, -3.0, 3.0)
rand = Random();
for i in range(500):
               h1.fill(rand.nextGaussian(),rand.nextGaussian())
c1.draw(h1);

# export to some image (png,eps,pdf,jpeg...)
# c1.export(Editor.DocMasterName()+".png")

Surface plots

Here is an example of surface plots:

DMelt example: Histogram as  a 3D surface in jzy3d + animation

from jhplot import *
from java.awt import Color
from java.util import Random

c1=HPlotXYZ("test",600,400)
c1.setGTitle("3D function")
c1.visible()
c1.setTickDecimalAll(1)
hh=H2D("Histogram",20,-2,2,20,-20,20)
rand = Random()
for i in range(10000):
      hh.fill(rand.nextGaussian(),5*rand.nextGaussian())

c1.setLegendBar()
c1.addAsSurface(hh)
c1.animate()
c1.update()

Scattered data

Here is an example that use two data points (blue and red):

DMelt example: Show a galaxy in 3D

from jhplot  import *
from java.util import Random
from java.awt import Color

c1 = HPlot3D("Canvas",500,500)
c1.setGTitle("Interactive 3D galaxy") 
c1.setRange(-10,10,-10,10,-10,10)
c1.setNameX("X")
c1.setNameY("Y")
c1.visible(1)


# create P2D objects in 3D 
p1= P2D("Galaxy")
p1.setSymbolSize(2);
p1.setSymbolColor(Color.blue);

rand = Random()
for i in range(5000):
      x=3*rand.nextGaussian()
      y=3*rand.nextGaussian()
      z=0.4*rand.nextGaussian()
      p1.add(x,y,z)
c1.draw(p1)

h2=P2D("Core")
h2.setSymbolSize(2) 
h2.setSymbolColor(Color.yellow)
for i in range(5000):
      x=0.9*rand.nextGaussian()
      y=0.9*rand.nextGaussian()
      z=0.8*rand.nextGaussian()
      h2.add(x,y,z)
c1.draw(h2)

Mixed plots

One can overlay scattered data with surface plots, bar plots in arbitrary way. Typically, you need to use jhplot.HPlot3D jhplot.HPlot3D canvas.

Example code

This tutorial is provided under this license agreement.