 |
Show two types of points with different color in 3D HVisAd
Source code name: "hvisadd_list2_dots.py"
Programming language: Python
Topic: Plots/3D
DMelt Version 1.9. Last modified: 07/10/1971. License: Pro
https://datamelt.org/code/cache/hvisadd_list2_dots_7036.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.
from java.awt import *
from visad import Display,RealTupleType,ScalarMap,RealType
from visad import FunctionType,FlatField,Irregular3DSet,DataReferenceImpl
from jhplot import *
from java.util import Random
c1=HVisAd()
display=c1.getDisplay()
XX = RealType("X")
YY = RealType("Y")
ZZ = RealType("Z")
weight = RealType("weight")
domain_tuple = RealTupleType(XX,YY,ZZ)
# fill random numbers
r=Random()
X,Y,Z=[],[],[]
sss=[]
for j in range(10000):
if (j<1000):
X.append(r.nextGaussian())
Y.append(r.nextGaussian())
Z.append(r.nextGaussian())
sss.append(1)
else: # data shifted and with different color (weight)
X.append(r.nextGaussian()+2)
Y.append(r.nextGaussian()+2)
Z.append(r.nextGaussian())
sss.append(3)
ntuple=[X,Y,Z]
domain_set = Irregular3DSet(domain_tuple, ntuple)
print domain_set
# this part add colors to data points
values=[]
values.append([sss][0])
ftype = FunctionType(domain_tuple, weight)
field = FlatField(ftype, domain_set)
field.setSamples(values, False)
# put some colors
dR=display.getDisplayRenderer()
dR.setForegroundColor(Color.gray)
dR.setBackgroundColor(Color.black)
dR.setCursorColor(Color.red)
# X, Y are the usual axes
mX=ScalarMap( XX, Display.XAxis )
mY=ScalarMap( YY, Display.YAxis )
mZ=ScalarMap( ZZ, Display.ZAxis )
az = mZ.getAxisScale() # show Z axis in color
az.setColor(Color.yellow)
mX.setScalarName("X")
mY.setScalarName("Y")
mZ.setScalarName("Z")
display.addMap( mX )
display.addMap( mY )
display.addMap( mZ )
# color for points
color = ScalarMap(weight, Display.RGBA)
display.addMap(color)
# Create a data reference and set the FlatField as our data
data_ref = DataReferenceImpl("data_ref")
data_ref.setData(field)
display.addReference( data_ref )
c1.visible()
You see the box below because you did not login.